API Design Flashcards
What REST stands for?
- REST stands for Representational State Transfer which is a web standards based architecture and uses HTTP Protocol for data communication.
- It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods.
- REST uses various representations to represent a resource like text, JSON and XML. Now a days JSON is the most popular format being used in web services.
Mention some key characteristics of REST?
REST is stateless, therefore the SERVER has no state (or session data)
Explain the architectural style for creating web API?
- HTTP for client server communication
- XML/JSON as formatting language
- Simple URI as the address for the services
- Stateless communication
What are resources in a REST architecture?
- REST architecture treats every content as a resource. These resources can be Text Files, Html Pages, Images, Videos or Dynamic Business Data. REST Server simply provides access to resources and REST client accesses and modifies the resources.
What are advantages of REST web services?
- Learning curve is easy since it works on HTTP protocol
- Supports multiple technologies for data transfer such as text, xml, json, image etc.
- No contract defined between server and client, so loosely coupled implementation.
- REST methods can be tested easily over browser.
What are the core components of a HTTP Request?
A HTTP Request has five major parts −
- Verb− Indicate HTTP methods such as GET, POST, DELETE, PUT etc.
- URI− Uniform Resource Identifier (URI) to identify the resource on server.
- HTTP Version− Indicate HTTP version, for example HTTP v1.1 .
- Request Header− Contains metadata for the HTTP Request message as key-value pairs. For example, client ( or browser) type, format supported by client, format of message body, cache settings etc.
- Request Body− Message content or Resource representation.
What are the core components of a HTTP response?
Status / Response Code- Indicate Server status for the requested resource. For example 404 means resource not found and 200 means response is ok.
HTTP Version- Indicate HTTP version, for example HTTP v1.3
Response Header- Contains metadata for the HTTP Response message as key-value pairs. For example, content length, content type, response date, server type etc.
Response Body- Response message content or Resource representation.
What are the best practices to create a standard URI for a web service?
Following are important points to be considered while designing a URI −
- Use Plural Noun− Use plural noun to define resources. For example, we’ve used users to identify users as a resource.
- Avoid using spaces− Use underscore(_) or hyphen(-) when using a long resource name, for example, use authorized_users instead of authorized%20users.
- Use lowercase letters− Although URI is case-insensitive, it is good practice to keep url in lower case letters only.
- Maintain Backward Compatibility− As Web Service is a public service, a URI once made public should always be available. In case, URI gets updated, redirect the older URI to new URI using HTTP Status code, 300.
- Use HTTP Verb− Always use HTTP Verb like GET, PUT, and DELETE to do the operations on the resource. It is not good to use operations names in URI.