Rest Flashcards

1
Q

What is REST Web Services?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain the architectural style for creating web api?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the HTTP methods supported by REST?

A
  • GET
  • POST
  • PUT
  • DELETE
  • OPTIONS
  • HEAD
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are resources in a REST architecture?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Mention some key characteristics of REST?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain how JAXB related to RESTful web api?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between PUT and POST?

A

“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 “

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which markup language can be used in RESTful API?

A

JSON and XML are the two markup language that can be used in Restful web api

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

List out the tools or API for developing or testing web api?

A
Testing tools for web services for REST APIs includes •Spring REST 
•Jersey (Oracle) 
•CXF (Apache) 
•Restlet 
•REST Easy (JBOSS)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which protocol is used by RESTful webservices?

A

RESTful web services make use of HTTP protocol as a medium of communication between client and server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is messaging in RESTful webservices?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the core components of a HTTP Request?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the core components of a HTTP response?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is URI?

A

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://

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is statelessness in RESTful Webservices?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the purpose of HTTP Status Code?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What HTTP Status Code 200 states?

A

It means, OK, shows success.

18
Q

What HTTP Status Code 201 states?

A

It means, CREATED, when a resource is successful created using POST or PUT request. Return link to newly created resource using location header.

19
Q

What HTTP Status Code 204 states?

A

It means, NO CONTENT, when response body is empty for example, a DELETE request.

20
Q

What HTTP Status Code 400 states?

A

It means, BAD REQUEST, states that invalid input is provided e.g. validation error, missing data.

21
Q

What HTTP Status Code 403 states?

A

It means, FORBIDDEN, states that user is not having access to method being used for example, delete access without admin rights.

22
Q

What HTTP Status Code 404 states?

A

It means, NOT FOUND, states that method is not available.

23
Q

What HTTP Status Code 500 states?

A

It means, INTERNAL SERVER ERROR, states that server has thrown some exception while executing the method.

24
Q

What are the best practices to be followed while designing a secure RESTful web service?

A

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.

25
Q

What is RESTful Web Services?

A

RESTFUL is referred for web services written by applying REST architectural concept are called RESTful services, it focuses on system resources and how state of resource should be transported over HTTP protocol to a different clients written in different language.

26
Q

What are RESTFUL web service used to perform CRUD?

A

In RESTFUL web service http methods like GET, POST, PUT and DELETE can be used to perform CRUD operations.

27
Q

What is URI?

A

Uniform Resource Identifier

28
Q

What does a URI do?

A

URI is a string of characters used to identify a resource. Such identification enables interaction with representations of the resource over a network, typically the World Wide Web, using specific protocols. Schemes specifying a concrete syntax and associated protocols define each URI. The most common form of URI is the Uniform Resource Locator (URL), frequently referred to informally as a web address.

29
Q

What is Stateless Communication?

A

A stateless protocol is a communications protocol that treats each request as an independent transaction that is unrelated to any previous request so that the communication consists of independent pairs of request and response. A stateless protocol does not require the server to retain session information or status about each communications partner for the duration of multiple requests. In contrast, a protocol that requires keeping of the internal state on the server is known as a stateful protocol.

30
Q

What is HTTP Get?

A

GET: It requests a resource at the request URL. It should not contain a request body as it will be discarded. May be it can be cached locally or on the server.

31
Q

What is HTTP Post?

A

POST: It submits information to the service for processing; it should typically return the modified or new resource

32
Q

What is HTTP Put?

A

PUT: At the request URL it update the resource

33
Q

What is HTTP Delete?

A

DELETE: At the request URL it removes the resource

34
Q

What is HTTP Option?

A

OPTIONS: It indicates which techniques are supported

35
Q

What is HTTP Head?

A

HEAD: About the request URL it returns meta information

36
Q

What are advantages of REST web services?

A

Some of the advantages of REST web services are:

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 is a lightweight protocol

REST methods can be tested easily over browser.

37
Q

What are disadvantages of REST web services?

A

Some of the disadvantages of REST are:

Since there is no contract defined between service and client, it has to be communicated through other means such as documentation or emails.

Since it works on HTTP, there can’t be asynchronous calls.

Sessions can’t be maintained.

38
Q

What is a Resource in Restful web services?

A

Resource is the fundamental concept of Restful architecture. A resource is an object with a type, relationship with other resources and methods that operate on it. Resources are identified with their URI, HTTP methods they support and request/response data type and format of data.

39
Q

What is the use of Accept and Content-Type Headers in HTTP Request?

A

These are important headers in Restful web services. Accept headers tells web service what kind of response client is accepting, so if a web service is capable of sending response in XML and JSON format and client sends Accept header as “application/xml” then XML response will be sent. For Accept header “application/json”, server will send the JSON response.

Content-Type header is used to tell server what is the format of data being sent in the request. If Content-Type header is “application/xml” then server will try to parse it as XML data. This header is useful in HTTP Post and Put requests.

40
Q

What is JAX-RS API?

A

Java API for RESTful Web Services (JAX-RS) is the Java API for creating REST web services. JAX-RS uses annotations to simplify the development and deployment of web services. JAX-RS is part of JDK, so you don’t need to include anything to use it’s annotations.

41
Q

Name some implementations of JAX-RS API?

A

Jersey: Jersey is the reference implementation provided by Sun. For using Jersey as our JAX-RS implementation, all we need to configure its servlet in web.xml and add required dependencies. Note that JAX-RS API is part of JDK not Jersey, so we have to add its dependency jars in our application.

RESTEasy: RESTEasy is the JBoss project that provides JAX-RS implementation.

42
Q

Name important annotations used in JAX-RS API?

A

@Path: used to specify the relative path of class and methods. We can get the URI of a webservice by scanning the Path annotation value.

@GET, @PUT, @POST, @DELETE and @HEAD: used to specify the HTTP request type for a method.

@Produces, @Consumes: used to specify the request and response types.

@PathParam: used to bind the method parameter to path value by parsing it.