REST API Flashcards
What does REST stand for?
Representational State Transfer
How many principles are there for creating a REST API?
5
Name the principles for creating REST APIs
- Separate the API into logical resources,
- Provide resources based on URLs,
- Never add an HTTP method in the name of an endpoint,
- Only send and receive data in JSON format
- The API should always be stateless
Explain the first principle ‘Separate the API into logical resources’
Divide your API into distinct resources that the client can interact with individually, each resource should be named using a noun. NEVER use a verb to name a resource
Explain the second principle ‘Provide resources based on URLs’
Resources should be accessible through a URL of the format: main_url/endpoint
Explain the third principle ‘Never add an HTTP method in the name of an endpoint’
There should never be HTTP methods for an endpoint or resources, regardless of the method for that resource the endpoint should always have the same name
Explain the fourth principle ‘Only send and receive data in JSON format’
It is self-explanatory, sending JSON should be of the format {status: ‘success/failed’, data/message: {data}/’error_message’}
Explain the fifth principle ‘The API should always be stateless’
It means the server should never have to keep track of anything on the client to send back a response, all the information needed for a response should be provided by the client in the request