Restful Web Services

Restful Web Services

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

Common HTTP Methods

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (89)

Section 1

(50 cards)

Common HTTP Methods

Front

GET, PUT, DELETE, POST, OPTIONS

Back

What is messaging in RESTful webservices

Front

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.

Back

Use Plural Noun

Front

Use plural noun to define resources. For example, we've used users to identify users as a resource.

Back

What are the core components of a HTTP Request

Front

Request has five major parts: Verb, URI, HTTP Version, Request Header, Request Body

Back

What is the purpose of HTTP Verb in REST based webservices

Front

VERB identifies the operation to be performed on the resource.

Back

DELETE

Front

Used to remove a resource

Back

What are the best practices to create a standard URI for a web service

Front

Important points Use Plural Noun, Avoid using spaces, Use lowercase letters, maintain backward compatibility, use HTTP verb

Back

What is the purpose of a URI in REST based webservices

Front

Purpose of an URI is to locate a resource(s) on the server hosting the web service.

Back

POST

Front

Used to update an existing resource or create a new resource

Back

Use lowercase letters

Front

Although URI is case-insensitive, it is good practice to keep url in lower case letters only.

Back

HTTP Response Example of 404

Front

Back

Status/Response Code

Front

core component of a HTTP Response Indicate Server status for the requested resource. For example 404 means resource not found and 200 means response is ok.

Back

What is URI

Front

URI stands for Uniform Resource Identifier. Each resource in REST architecture is identified by its URI.

Back

Completeness

Front

A design best practice Format should be able to represent a resource completely. For example, a resource can contain another resource. Format should be able to represent simple as well as complex structures of resources.

Back

HTTP Request Example of POST

Front

Back

PUT

Front

Used to create a new resource

Back

HTTP Request Specific Header Fields

Front

accept* authorization* cookie expect from host referer user-agent

Back

Response Body

Front

core component of a HTTP Response Response message content or Resource representation.

Back

HTTP Request Example of Get

Front

Back

Request Header

Front

core component of a HTTP Request 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.

Back

What are webservices

Front

A web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks like the Internet in a manner similar to inter-process communication on a single computer

Back

Response Header

Front

core component of a HTTP Response Contains metadata for the HTTP Response message as key-value pairs. For example, content length, content type, response date, server type etc.

Back

OPTIONS

Front

Used to get the supported operations on a resource

Back

Understandability

Front

A design best practice Both Server and Client should be able to understand and utilize the representation format of the resource.

Back

What do you mean by idempotent operation

Front

these operations means their result will always be the same no matter how many times these operations are invoked

Back

What is the format of a URI in REST architecture

Front

A URI is of following format − <protocol>://<serviceName>/<ResourceType>/<ResourceID>

Back

HTTP Header Fields

Front

cache-control connection date pragma trailer transfer-encoding upgrade via warning

Back

HTTP Version

Front

core component of a HTTP Request Indicate HTTP version, for example HTTP v1.1

Back

Disadvantage of statelessness

Front

Web services need to get extra information in each request and then interpret to get the client's state in case client interactions are to be taken care of.

Back

What is a resource in REST

Front

REST uses various representations to represent a resource where text, JSON, XML. XML and JSON are the most popular representations of resources.

Back

What are best practices to design a resource representation

Front

Understandability, Completeness, Linkability

Back

HTTP Response Specific Header Fields

Front

age location retry-after server set-cookie content-language content-length* content-location content-type* expires last-modified

Back

REST stands for

Front

REpresentational State Transfer

Back

GET

Front

Provides a read only access to a resource

Back

Maintain backward compatibility

Front

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.

Back

Advantages of statelessness

Front

Web services can treat each method request independently. Web services need not to maintain client's previous interactions. It simplifies application design. As HTTP is itself a statelessness protocol, RESTful Web services work seamlessly with HTTP protocol.

Back

What are RESTful webservices

Front

Web services based on REST Architecture are known as RESTful web services. These web services use HTTP methods to implement the concept of REST architecture. A RESTful web service usually defines a URI, Uniform Resource Identifier a service, provides resource representation such as JSON and set of HTTP Methods.

Back

HTTP Response Example of 200

Front

Back

What is REST

Front

web standards based architecture and uses HTTP Protocol for data communication. It resolves around resource where ever component is a resource and a resource is accessed by a common interface using HTTP standard methods. In REST architecture, a REST Server simply provides access to resources and REST client accesses and presents the resources. Here each resource is identified by URIs/ global IDs. 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.

Back

Request Body

Front

core component of a HTTP Request Message content or Resource representation.

Back

Avoid using spaces

Front

Use underscore(_) or hyphen(-) when using a long resource name, for example, use authorized_users instead of authorized%20users.

Back

use http verb

Front

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.

Back

URI

Front

core component of a HTTP Request Uniform Resource Identifier (URI) to identify the resource on server.

Back

What is statelessness in RESTful webservices

Front

The client's application state should never be stored on the server, but passed around from the client to every place that needs it. That is where the ST in REST comes from, State Transfer. You transfer the state around instead of having the server store it. This is the only way to scale to millions of concurrent users. If for no other reason than because millions of sessions is millions of sessions.

Back

Verb

Front

core component of a HTTP Request Indicate HTTP methods such as GET, POST, DELETE, PUT etc.

Back

Likability

Front

A design best practice A resource can have a linkage to another resource, a format should be able to handles such situations.

Back

HTTP Version

Front

core component of a HTTP Response Indicate HTTP version, for example HTTP v1.1 .

Back

Core components of a HTTP response

Front

Four major parts: Status/Response Code, HTTP Version, Response Header, Response Body

Back

What is addressing in RESTful webservices

Front

Addressing refers to locating a resource or multiple resources lying on the server. It is analogous to locate a postal address of a person.

Back

Which protocol is used by RESTful webservices?

Front

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

Back

Section 2

(39 cards)

What should be the purpose of HEAD method of RESTful web services

Front

it should return only HTTP header, no body and should be read only

Back

What methods are safe

Front

GET, HEAD, OPTIONS and TRACE methods are defined as safe, meaning they are only intended for retrieving data

Back

What is caching

Front

Caching refers to storing server response in client itself so that a client needs not to make server request for same resource again and again. A server response should have information about how a caching is to be done so that a client caches response for a period of time or never caches the server response.

Back

HTTP Status Code 401

Front

FORBIDDEN user does not have access to method. ex) DELETE without admin rights

Back

What is JAX-RS

Front

JAX-RS stands for JAVA API for RESTful Web Services. JAX-RS is a JAVA based programming language API and specification to provide support for created RESTful Webservices. Its 2.0 version was released in 24 May 2013. JAX-RS makes heavy use of annotations available from Java SE 5 to simplify development of JAVA based web services creation and deployment. It also provides supports for creating clients for RESTful web services.

Back

serialization

Front

Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link. The byte stream can then be deserialized - converted into a replica of the original object. In Java, the serialization mechanism is built into the platform, but you need to implement the Serializable interface to make an object serializable.

Back

What methods are unsafe

Front

PUT POST DELETE PATCH

Back

What HTTP response provides the date and time of the resource when it was created

Front

date

Back

No sensitive data in URL

Front

Best Practices for designing a restful webservice Never use username, password or session token in URL , these values should be passed to Web Service via POST method.

Back

What should be the purpose of OPTIONS method of RESTful web services

Front

It should list down the supported operations in a web service and should be read only This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval. Response Header: Server: Apache/2.4.1 (Unix) OpenSSL/1.0.0g Allow: GET,HEAD,POST,OPTIONS,TRACE Response Body Most likely JSON specifying all the actions/parameters/etc

Back

HTTP Status Code 500

Front

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

Back

Restriction on Method execution

Front

Best Practices for designing a restful webservice Allow restricted use of methods like GET, POST, DELETE. GET method should not be able to delete data.

Back

What HTTP response provides the date and time of the resource when it was last modified

Front

last modified

Back

Which directive of Cache Control Header of HTTP response provides indication to server to revalidate resource if max-age has passed?

Front

must-revalidate Cache-control: must-revalidate

Back

Which directive of Cache Control Header of HTTP response indicates that resource is cachable by only client and server, no intermediary can cache the resource?

Front

private cache-control:private

Back

HTTP Status Code 304

Front

NOT MODIFIED used to reduce network bandwith usage in case of conditional GET requests. response body should be empty headers should have date and location

Back

What HTTP response sets expiration date and time of caching

Front

expires

Back

HTTP Status Code 400

Front

BAD REQUEST there was invalid input, validation error, missing data

Back

Session based authentication

Front

Best Practices for designing a restful webservice Use session based authentication to authenticate a user whenever a request is made to a Web Service method.

Back

API

Front

application programming interface

Back

HTTP Status Code 204

Front

NO CONTENT a response body is empty, for example a DELETE request

Back

Which directive of Cache Control Header of HTTP response indicates that resource is cachable by any component?

Front

public cache-control:public

Back

Which directive of Cache Control Header of HTTP response indicates that resource is not cachable?

Front

no-cache Cache-control: no-cache

Back

Throw generic error messages

Front

Best Practices for designing a restful webservice A web service method should use HTTP error messages like 403 to show access forbidden etc.

Back

what is the difference between put and post

Front

PUT and POST operation are nearly same with the difference lying only in the result where PUT operation is idempotent and POST operation can cause different result.

Back

What is the purpose of HTTP Status Code?

Front

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.

Back

What HTTP response provides control over chaching

Front

cache-control

Back

Validate Malformed XML/JSON

Front

Best Practices for designing a restful webservice Check for well formed input passed to a web service method.

Back

HTTP Status Code 201

Front

CREATED a resource is successfully created using POST or PUT

Back

HTTP Status Code 404

Front

NOT FOUND the method is not available

Back

HTTP Status Code 409

Front

CONFLICT conflict situation while executing the method for example, adding duplicate entry

Back

HTTP Status Code 200

Front

OK, Success

Back

Validation

Front

Best Practices for designing a restful webservice Validate all inputs on the server. Protect your server against SQL or NoSQL injection attacks.

Back

which type of webservices methods are idempotent

Front

PUT DELETE HEAD OPTIONS GET

Back

What are the best practices for caching?

Front

Always keep static contents like images, css, JavaScript cacheable, with expiration date of 2 to 3 days. Never keep expiry date too high. Dynamic contents should be cached for few hours only.

Back

Which directive of Cache Control Header of HTTP response can set the time limit of caching?

Front

max-age cache-control: max-age= seconds

Back

PUT vs POST

Front

POST sends data to a specific URI and expects the resource at that URI to handle the request. The web server at this point can determine what to do with the data in the context of the specified resource. The POST method is not idempotent, however POST responses are cacheable so long as the server sets the appropriate Cache-Control and Expires headers. PUT puts a file or resource at a specific URI, and exactly at that URI. If there's already a file or resource at that URI, PUT replaces that file or resource. If there is no file or resource there, PUT creates one. PUT responses are not cacheable.For instance, if you know that an article resides at http://example.org/article/1234, you can PUT a new resource representation of this article directly through a PUT on this URL. With PUT requests, you MUST send all the available properties/values, not just the ones you want to change.

Back

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

Front

Best Practices: Validation, Session based authentication, no sensitive data in URL, restriction on method execution, validate malformed xml/json, throw generic error messages

Back

which type of webservices methods are to be read only

Front

GET

Back