- Resources can have `one-to-one`, `one-to-many`, and `many-to-many` relationships etc. Mapping them correctly is crucial.
- **One-to-One** Mapping
For example, `Countries/1/capital` suggests a one-to-one relationship between a country and a capital city. This means a country can only have one capital. This type of relationship means that one row relates only to one row in another table (one country, one capital in two different tables). This type of relationship is not common and is often used to break up the amount of data in one row of a table.
For example, `Tickets/145/messages/4` suggests one-to-many relationship between `tickets` and `messages`. Meaning `1` ticket has `N` messages. Message isn't standalone resource. You can't have `/messages/4`.
For example, `/usergroups/345/users/56` suggests select 345th user group and get user with id 56. However, one user might be in multiple `usergroups` i.e. `/usergroups/209/users/56` is also valid. In such case so for seperating the dependant resource `users` into a seperate endpoint like `/users/56` and provide resource linking in `/usergroups/209/users/56`
- **Header** : Should contain global or platform wide data. E.g. API key parameters, encrypted keys for auth, device type information e.g. mobile or desktop or endpoint, device data type e.g. xml or json. Use header to communicate these parameters
- #### HTTP Status Codes
Use correct status codes
| Codes | Meaning |
| ------------- |:-------------:|
| 1xx | Request received and understood. |
| 2xx | Action requested by client was received, understood and requested. |
| 3xx | Client must take additional action to complete the request. Most of these status codes are used in URL Redirection. |
| 4xx | Intended for situations where it seems the error was caused by the client. |
| 5xx | The server failed to fulfil a request. |
Little more on **2xx**!
- **201 Resource Created.**
POST `/cars` should return HTTP 201 created with `location` header stating how to access the resource
E.g. `location` : `api.com/cars/124` in header
- **202 - Accepted**
Use this if the task is huge to run. Tell the client, it has accepted the request and will/is process/processing
No payload is returned
-**204 - No content**
Used when deleted `DELETE cars/124`
Returns no content. But can also return `200 OK` if API intends to send the deleted resource for further processing.