REST API
Content
1. What is an API
2. What is a REST API
3. REST Architectural Style
i. Architectures
ii. Overview of HTTP
iii. Message Formats
4. How to use REST APIs
What is an API
API - Application Programming Interface
API is a contract. A promise to perform described services when
asked in specific ways.
App
Its a set of functions, classes or objects that software module
exposes for other programs to use by passing arguments (inputs).
Usually API’s are used
to connect the two
different platforms
What is an API
Without APIs
Web app
Mobile apps
Web Server
Database
User
With APIs
Web app
Mobile app
REST API
Database
User
What is a REST API
REST - Representational State Transfer
REST is simply an architectural style achieved by combining a number of
different well-known architectures.
It be used to modify or view resources on the server without
performing any server-side operations.
Client-Server
Client
Server
Response
Request
Stateless
Client
Start Session
Client
ServerEnd Session
Stateless
The state is
managed by
the clientSession use to keep
track of client data
Cacheable
Server
Response
Request
Labeled
Data
Data Labeled
Data
intermediary servers or components Cache
App
Response
No
Yes
If it
cacheable
data
Uniform Interface
Client 1 Client 2 Client 3
API A
JAVA EE
MySQL
API B
.NET
SQL Server
API C
Node JS
Mongo DB
Abstraction
Layered System
Solution
SharedLayer Layer 2
Layer 3
Layer 1
Layered System
Solution
CommonUtilityLayer Business Logic Layer
Presentation Layer
Data Access Layer
Overview of HTTP
The most popular protocol used for RESTful implementations is HTTP.
REST architecture use HTML Verbs to make requests.
HTML Verbs - uniquely address data using a uniform and minimal set of
commands.
• GET - Read data or resources.
• POST - Create data or resource.
• PUT - Update data or resources.
• DELETE - Delete data or resources.
Message Formats
REST is not tied to a specific
message format.
• XML - Extensible Markup
Language
• JSON - JavaScript Object
Notation
<?xml version="1.0" encoding="UTF-8"?>
<Person>
<Name>Matt</Name>
<Surname>Van Der Westhuizen</Surname>
<Hobbies>
<Hobby>Boardgames</Hobby>
<Hobby>GameDev</Hobby>
<Hobby>Reading</Hobby>
</Hobbies>
<PhoneNumbers>
<PhoneNumber>
<Type>home</Type>
<Number>1234567890</Number>
</PhoneNumber>
<PhoneNumber>
<Type>cell</Type>
<Number>0821234567</Number>
</PhoneNumber>
</PhoneNumbers>
</Person>
{
"name": "Matt",
"surname": "Van Der Westhuizen",
"hobbies": [
"Boardgames",
"GameDev",
"Reading"
],
"phoneNumbers": [
{"type": "home", "number": "1234567890"},
{"type": "cell", "number": "0821234567"}
]
}
How to use REST APIs
Here is some examples in Google Map API
https://maps.googleapis.com/maps/api/geocode/json?&address=pitakotte
Extrogene Software Pvt Ltd. Place ID = ChIJS2KQ2d5b4joR4vOh1RaicjQ
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJS2
KQ2d5b4joR4vOh1RaicjQ&key=AIzaSyBXMUhoE8lu0wjm7SCO9RacyKE-
ef8J0Gw
Kanushka Gayan
SE intern @ Extrogene Software (Pvt) Ltd
kanushkanet@gmail.com
Thank You!

REST API

  • 1.
  • 2.
    Content 1. What isan API 2. What is a REST API 3. REST Architectural Style i. Architectures ii. Overview of HTTP iii. Message Formats 4. How to use REST APIs
  • 3.
    What is anAPI API - Application Programming Interface API is a contract. A promise to perform described services when asked in specific ways. App
  • 4.
    Its a setof functions, classes or objects that software module exposes for other programs to use by passing arguments (inputs). Usually API’s are used to connect the two different platforms What is an API
  • 5.
    Without APIs Web app Mobileapps Web Server Database User
  • 6.
    With APIs Web app Mobileapp REST API Database User
  • 7.
    What is aREST API REST - Representational State Transfer REST is simply an architectural style achieved by combining a number of different well-known architectures. It be used to modify or view resources on the server without performing any server-side operations.
  • 8.
  • 9.
    Stateless Client Start Session Client ServerEnd Session Stateless Thestate is managed by the clientSession use to keep track of client data
  • 10.
    Cacheable Server Response Request Labeled Data Data Labeled Data intermediary serversor components Cache App Response No Yes If it cacheable data
  • 11.
    Uniform Interface Client 1Client 2 Client 3 API A JAVA EE MySQL API B .NET SQL Server API C Node JS Mongo DB Abstraction
  • 12.
  • 13.
    Layered System Solution CommonUtilityLayer BusinessLogic Layer Presentation Layer Data Access Layer
  • 14.
    Overview of HTTP Themost popular protocol used for RESTful implementations is HTTP. REST architecture use HTML Verbs to make requests. HTML Verbs - uniquely address data using a uniform and minimal set of commands. • GET - Read data or resources. • POST - Create data or resource. • PUT - Update data or resources. • DELETE - Delete data or resources.
  • 15.
    Message Formats REST isnot tied to a specific message format. • XML - Extensible Markup Language • JSON - JavaScript Object Notation <?xml version="1.0" encoding="UTF-8"?> <Person> <Name>Matt</Name> <Surname>Van Der Westhuizen</Surname> <Hobbies> <Hobby>Boardgames</Hobby> <Hobby>GameDev</Hobby> <Hobby>Reading</Hobby> </Hobbies> <PhoneNumbers> <PhoneNumber> <Type>home</Type> <Number>1234567890</Number> </PhoneNumber> <PhoneNumber> <Type>cell</Type> <Number>0821234567</Number> </PhoneNumber> </PhoneNumbers> </Person> { "name": "Matt", "surname": "Van Der Westhuizen", "hobbies": [ "Boardgames", "GameDev", "Reading" ], "phoneNumbers": [ {"type": "home", "number": "1234567890"}, {"type": "cell", "number": "0821234567"} ] }
  • 16.
    How to useREST APIs Here is some examples in Google Map API https://maps.googleapis.com/maps/api/geocode/json?&address=pitakotte Extrogene Software Pvt Ltd. Place ID = ChIJS2KQ2d5b4joR4vOh1RaicjQ https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJS2 KQ2d5b4joR4vOh1RaicjQ&key=AIzaSyBXMUhoE8lu0wjm7SCO9RacyKE- ef8J0Gw
  • 17.
    Kanushka Gayan SE intern@ Extrogene Software (Pvt) Ltd kanushkanet@gmail.com Thank You!

Editor's Notes

  • #9 Client Server: This constraint provides separation of concerns, improves scalability and improves the portability of the interface.
  • #10 Stateless: This constraint requires that each request contains sufficient state for the server to understand what to do... this provides visibility, readability and scalability.
  • #11 Cacheable: This constraint requires that all responses from the service to its clients are explicitly labelled as cacheable or non-cacheable so that intermediary servers or components can cache responses. This improves efficiency, scalability and user-perceived performance.
  • #12 Uniform Interface: This constraint defines a simple standard for working with a REST service. It includes identification of resources by URI, manipulation of resources through representation, self-descriptive message and HATEOAS.
  • #13 Layered System: This constraint requires that a client should not be able to tell if it is connected to the end server or to an intermediary. Layered systems cause a reduction in performance, but this should be counteracted by caching.
  • #14 Layered System: This constraint requires that a client should not be able to tell if it is connected to the end server or to an intermediary. Layered systems cause a reduction in performance, but this should be counteracted by caching.