Rest Flashcards
What is REST Web Services?
REST is the acronym for REpresentational State Transfer. REST is an architectural style for developing applications that can be accessed over the network.
REST is a stateless client-server architecture where web services are resources and can be identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful web services. REST doesn’t specify any specific protocol to use, but in almost all cases it’s used over HTTP/HTTPS. When compared to SOAP web services, these are lightweight and doesn’t follow any standard. We can use XML, JSON, text or any other type of data for request and response.
Explain the architectural style for creating web api?
The architectural style for creating web api are
•HTTP for client server communication
•XML/JSON as formatting language
•Simple URI as the address for the services
•Stateless communication
What are the HTTP methods supported by REST?
- GET
- POST
- PUT
- DELETE
- OPTIONS
- HEAD
What are resources in a REST architecture?
Resources are identified by logical URLs; it is the key element of a RESTful design. Unlike SOAP web services, in REST you view the product data as a resource and this resource should contain all the required information.
Mention some key characteristics of REST?
- REST is stateless, so there is no storage of session data on the client
- With a well applied REST API, the server could be restarted between two calls as every data is passed to the server
- Web service mostly uses POST method to make operations, whereas REST uses GET to access resource
Explain how JAXB related to RESTful web api?
JAXB stands for Java API for Xml Binding. This framework is used to bind XML or JSON to Java objects without the need for creating XML or JSON parsers.
What is the difference between PUT and POST?
“PUT” puts a file or resource at a particular URI and exactly at that URI. If there is already a file or resource at that URI, PUT changes that file or resource. If there are no resource or file there, PUT makes one POST sends data to a particular URI and expects the resource at that URI to deal with the request. The web server at this point can decide what to do with the data in the context of specified resource “
Which markup language can be used in RESTful API?
JSON and XML are the two markup language that can be used in Restful web api
List out the tools or API for developing or testing web api?
Testing tools for web services for REST APIs includes •Spring REST •Jersey (Oracle) •CXF (Apache) •Restlet •REST Easy (JBOSS)
Which protocol is used by RESTful webservices?
RESTful web services make use of HTTP protocol as a medium of communication between client and server.
What is messaging in RESTful webservices?
A client sends a message in form of a HTTP Request and server responds in form of a HTTP Response. This technique is termed as Messaging. These messages contain message data and metadata i.e. information about message itself.
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?
A HTTP Response has four major parts − 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.1 .
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 is URI?
URI stands for Uniform Resource Identifier. Each resource in REST architecture is identified by its URI. Purpose of an URI is to locate a resource(s) on the server hosting the web service. A URI is of following format −
protocol://
What is statelessness in RESTful Webservices?
As per REST architecture, a RESTful web service should not keep a client state on server. This restriction is called statelessness. It is responsibility of the client to pass its context to server and then server can store this context to process client’s further request. For example, session maintained by server is identified by session identifier passed by the client.
What is the purpose of HTTP Status Code?
HTTP Status code are standard codes and refers to predefined status of task done at server. For example, HTTP Status 404 states that requested resource is not present on server.
What HTTP Status Code 200 states?
It means, OK, shows success.
What HTTP Status Code 201 states?
It means, CREATED, when a resource is successful created using POST or PUT request. Return link to newly created resource using location header.
What HTTP Status Code 204 states?
It means, NO CONTENT, when response body is empty for example, a DELETE request.
What HTTP Status Code 400 states?
It means, BAD REQUEST, states that invalid input is provided e.g. validation error, missing data.
What HTTP Status Code 403 states?
It means, FORBIDDEN, states that user is not having access to method being used for example, delete access without admin rights.
What HTTP Status Code 404 states?
It means, NOT FOUND, states that method is not available.
What HTTP Status Code 500 states?
It means, INTERNAL SERVER ERROR, states that server has thrown some exception while executing the method.
What are the best practices to be followed while designing a secure RESTful web service?
As RESTful web services work with HTTP URLs Paths so it is very important to safeguard a RESTful web service in the same manner as a website is be secured. Following are the best practices to be followed while designing a RESTful web service
Validation − Validate all inputs on the server. Protect your server against SQL or NoSQL injection attacks.
Session based authentication − Use session based authentication to authenticate a user whenever a request is made to a Web Service method.
No sensitive data in URL − Never use username, password or session token in URL , these values should be passed to Web Service via POST method.
Restriction on Method execution − Allow restricted use of methods like GET, POST, DELETE. GET method should not be able to delete data.
Validate Malformed XML/JSON − Check for well formed input passed to a web service method.
Throw generic Error Messages − A web service method should use HTTP error messages like 403 to show access forbidden etc.