Rest Api

You might also like

Download as odp, pdf, or txt
Download as odp, pdf, or txt
You are on page 1of 25

Introduction to

REST Web
Services
Vipin Raj . KP

Agenda

Web services

What is REST?

Resource Based URI

HTTP Methods

HTTP Response & Status Codes

Web Services

Services exposed to Internet for programmatic


access
Also called web APIs (Application Programming
Interface)

What is REST?

Stands for REpresentational State Transfer

Introduced by Roy Fielding

An architectural style or design criteria

Not a Standard

No service definition, no specification

Use HTTP requests to Update, Retrieve and Delete


data

Lightweight

Stateless, client-server, cacheable

What is REST?

REST

Web
Services

RESTful
Web
Services

Resource Based URI

Resource
Anything that is important enough to be referenced
in its singularity
Has a name
Can be container for other resources

Resource Based URI

Action based URI:


weatherapp.com/weatherLookup.do?zipcode=12345
does some action

Resource based URI:


weatherapp.com/zipcode/12345
weatherapp.com/zipcode/47343
lookup

Resource Based URI

Example: A social media API


profiles/{profileName}
profiles/dhruva

/messages/{messageId}
/messages/1
Rule: use Nouns, NO Verbs

Resource Based URI

/comments/{commentId} ?
/comments/12

A better URI:
/messages/{messageId}/comments/{commentId}
/messages/2/comments/1
also,
/messages/{messageId}/likes/{likeId}
/messages/{messageId}/shares/{shareId}
Resource relations

Resource Based URI

Collection URIs

/messages/{messageId}/comments
Returns all comments for a message

/messages
Returns all messages

/profiles
Returns all profiles

Resource Based URI

Collection URIs Filtering Results


/messages?year=2016&offset=22&limit=10
uses query parameters

HTTP Methods

GET Requests a resource at the request URL


POST Submits information to the service for
processing

PUT Add a new resource at the request URL

DELETE Removes the resource at the request URL

OPTIONS Indicates which methods are supported

HEAD Returns meta information about the request


URL

HTTP Methods

HTTP Methods

HTTP Methods

HTTP Methods

HTTP Methods

HTTP Methods

HTTP Methods

HTTP Response & Status Codes

JSON/XML

HTTP Response & Status Codes

Use HTTP Response Headers to identify the type of


response
eg:
Content Type : application/json

Content negotiation using Request header


eg:
Accept : application/json

HTTP Response & Status Codes

Status Codes
First line of every HTTP Response contain a Status
code
1xx
2xx
3xx
4xx
5xx

Informational
Success
Redirection
Client Error
Server Error

HTTP Response & Status Codes

Status Codes

HTTP Response & Status Codes

Status Codes

Thank You!

You might also like