Skip to content

Commit 08d4ff5

Browse files
committed
updated api study notes
1 parent fa84edf commit 08d4ff5

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

docs/api-study.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [Intro](#intro)
1010
* [RESTful API Concepts](#rest)
1111
- [Definitions](#rest-def)
12+
- [Resource types](#rest-res-types)
1213
- [Applications and Services](#rest-app)
1314
- [API Versions](#rest-ver)
1415
- [Resources & Collections](#rest-res)
@@ -60,6 +61,23 @@
6061
- query: "?name=John"
6162
- State: application state that has the resources
6263

64+
65+
<a name="rest-res-types"></a>
66+
### Resource Types
67+
68+
* **Document**: a singular concept that is akin to an object instance or database record. e.g.: http://api.soccer.restapi.org/leagues/seattle/teams/trebuchet
69+
70+
* **Collection**: a server-managed directory of resources. Clients may propose new resources to be added to a collection. However, it is up to the collection to choose to create a new resource, or not. Example: http://api.soccer.restapi.org/leagues/seattle/teams
71+
72+
* **Store**: a client-managed resource repository. A store resource lets an API client put resources in, get them back out, and decide when to delete them. On their own, stores do not create new resources; therefore a store never generates new URIs. Instead, each stored resource has a URI that was chosen by a client when it was initially put into the store. Example: `PUT /users/1234/favorites/alonso`.
73+
74+
* **Controller**: models a procedural concept.
75+
- Controller resources are like executable functions, with parameters and return values; inputs and outputs. Like a traditional web application's use of HTML forms, a REST API relies on controller resources to perform application-specific actions that cannot be logically mapped to one of the standard methods (create, retrieve, update, and delete, also known as CRUD).
76+
- Controller names typically appear as the last segment in a URI path, with no child resources to follow them in the hierarchy.
77+
- **Note**: Controller resource remains argument about "resource must be a noun, instead of a verb".
78+
- Example: `POST /alerts/245743/resend`
79+
80+
6381
<a name="rest-app"></a>
6482
### Applications and Services
6583

@@ -146,6 +164,12 @@ A resource-oriented API is generally modeled as a resource hierarchy, where each
146164
- `GET`, `PUT`, `PATCH`, `POST`, `DELETE` (CRUD)
147165
- `HEAD`, `OPTIONS`, `CONNECT`, `TRACE`
148166
167+
* Usages:
168+
- Checking whether a resource has changed. This is useful when maintaining a cached version of a resource (`HEAD`).
169+
- Checking whether a resource exists and is accessible (`HEAD`, `OPTIONS`). For example, validating user-submitted links in an application.
170+
- Retrieving metadata about the resource, e.g. its media type or its size, before making a possibly costly retrieval (`HEAD`).
171+
- Identifying which HTTP methods a resource supports (`OPTIONS`).
172+
149173
* RESPONSE: representation of resource, easy to read and implemented into applications, e.g. REST XML-RPC SOAP JSON Serialized PHP
150174
151175
* API is like a bunch of useful methods or functions, parameters is like the parameters we can pass on to these methods
@@ -170,6 +194,7 @@ A resource-oriented API is generally modeled as a resource hierarchy, where each
170194
| Date |RFC 5322 Date|GMT/UTC timestamp of the request.|
171195
| Accept |Content type |(Hint of) the requested content type for the response, e.g. `application/json` or `text/javascript` (for JSONP).|
172196
| Accept-encoding |gzip, deflate|REST endpoints SHOULD support GZIP and DEFLATE encoding, when applicable. For very large resources, services MAY ignore and return uncompressed data.|
197+
| Allow ||List of allowed methods a resource supports, thru `OPTIONS` request, e.g. `Allow: GET,HEAD,POST,OPTIONS,TRACE`.|
173198
| If-Match ||Only if the request matches one of listed `ETags`.|
174199
| If-Modified-Since||Response 304 w/o body if no change; otherwise 200 w/ latest.|
175200
| Prefer ||return=minimal,<br/>return=representation|
@@ -196,9 +221,9 @@ A resource-oriented API is generally modeled as a resource hierarchy, where each
196221
* `200 OK` or `204 No Content` for `PUT` method success
197222
* `200 OK` for other methods success
198223
- `202 Accepted` (long-running operation, with `Location` in header)
199-
- `203 Non-Authoritative Information`
200-
- `204 No Content`
201-
- `205 Reset Content`
224+
- `203 Non-Authoritative Information` (enclosed payload has been modified from that of the origin server's 200 OK response by a transforming proxy)
225+
- `204 No Content` (success but additional content in the response payload body)
226+
- `205 Reset Content` (desires the user agent to reset the "document view")
202227
- `206 Partial Content`
203228
* `3xx` (Redirection)
204229
- `300 Multiple Choices`
@@ -228,7 +253,9 @@ A resource-oriented API is generally modeled as a resource hierarchy, where each
228253
- `503 Service Unavailable`
229254
(simply refuse, or may with `Retry-After` header on temporary overloaded or scheduled maintenance)
230255
- `504 Gateway Timeout`
231-
* See [more](https://www.restapitutorial.com/httpstatuscodes.html)
256+
* See
257+
- [httpstatuses](https://httpstatuses.com/)
258+
- [more](https://www.restapitutorial.com/httpstatuscodes.html)
232259
233260
234261
<br/><a name="design"></a>

0 commit comments

Comments
 (0)