Representational State Transfer is an architectural style for distributed hypermedia systems.
Basics | |
---|---|
Resource | Any information, content, object |
Resourse representation | Representation: state of the resource. Data, metadata, hypermedia links. |
Common media-types | JSON, XML, HTML |
Methods | GET, PUT, POST, DELETE PATCH, OPTIONS, HEAD, TRACE |
Resource Types |
---|
document |
collection |
store |
controller |
Versioning, use when |
---|
Change in the format of the response data |
Change in the response type |
Removing any part of the API |
Versioning methods | |
---|---|
URI | https://host.com/api/v1/customers/748229 https://apiv1.host.com/customers/748229 |
Custom Request Header | Accept-version: v1 Accept-version: v2 |
Accept Header | vnd.ims.lis.v2.result+json |
Idempotency | |
---|---|
POST | No |
GET, PUT, DELETE, PATCH, OPTIONS, HEAD, TRACE | Yes |
REST Principles |
---|
Client–server |
Stateless |
Uniform interface |
Cacheable |
Layered system |
Code on demand(optional) |
Naming conventions | |
---|---|
singleton | /customers/{customer-id} |
collection | /customers |
sub-collection | /customers/{customer-id}/accounts |
REST URI Naming |
---|
Nouns only |
Use hyphens (-) |
Use lowercase |
No file extensions in URI |
No CRUD function names |
Security |
---|
SSL, HTTPS |
OAuth |
JWT |
Basic authorization |
Request timestamp |
Password hash |
HATEOAS |
---|
Hypermedia as the Engine of Application State |