Web API Design記錄

看了「Web API Design」這堂課,所以將它記錄一下

看了「Web API Design」這堂課,所以將它記錄一下,

1.URI Design

/getCustomers or /api/Customers
/getInvoice/123 or /api/Invoice/Q1234
/api/Customers/123/Invoices
/api/Customers?page=123

 

2.Formatting Results

/api/Customers?format=json
/api/Customers.json
/api/Customers?format=jsonp&callback=fooCallback

 

3.Entity Tags(ETags) (Cache)

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
ETag:W/"1233023942098"
Content-Length:639

GET /api/Invoice/Q1234 HTTP/1.123
Accept:application/json, text/xml
If-None-Match:"1233023942098"

 

4.Paging

/api/Customers?page=3&pageSize=10

Result如下,
{
"totalResults":32161
"nextPage":"http://.../api/Customers?page=4",
"prevPage":"http://.../api/Customers?page=2",
"result":[....]
}

 

5.Partial Items

/api/Customers/123?fields=id,name,otherFields..

 

6.Version

api.tumblr.com/v3/Customers

api.Netflix.com/.../123?v=3.0

Content Type:application/vnd.github.3.param+json

Header
    x-ms-version:2014/03/25

 

7.Security

API Keys
OAuth
token

 

詳細說明,請參考「Web API Design」這堂課

Hi, 

亂馬客Blog已移到了 「亂馬客​ : Re:從零開始的軟體開發生活

請大家繼續支持 ^_^