REST APIs
What they are? How they work?
APIs
Application Programming Interface
interface that defines interactions between multiple software applications
API
UI
Interfaces for Humans
Interfaces for Software
An API defines...
- Contract: Procedures & Conventions
- Data formats
- Inputs: Calls / Requests
- Outputs: Results / Responses
APIs
- Mostly inflexible
- Ruled by Standards (Ex. IETF)
- Agnostic to programming lang(s)
- Mostly at lower network stack levels
- Wider applicability
- Highly flexible
- Custom Implementation
- Tied to programming language(s)
- At application level
- Specific applicability
- Relies on Protocols to work
Protocols
vs.
"You use an API, but speak a Protocol"
TCP/IP
UDP
Gopher
FTP
SSH/SFTP
Telnet
SMTP/POP3
HTTP(S)(2)
Protocols (10-100s)
Internet
Streaming
Hypertext
File Transfers
Remote Shells
World Wide Web
APIs (♾)
Libraries / Frameworks
libc, Tensorflow, OpenGL, Rails, protobufs
Operating Systems
POSIX, Win32, DCOM, CORBA, ...
Remote APIs
JDBC, RPC
Web APIs
HTTP, XML-RPC, SOAP, REST, gRPC, GraphQL
Service-specific APIs
Twitter, Stripe, Twilio, Thrillshare, ...
Web APIs
(mostly over HTTP*)
Client-Server model
HTTP
Text-based
<SGML>
- XML
- HTML
Multi-Media
JSON⭐️
Hypertext Transfer Protocol
hypermedia, hyperlinks
WWW (World Wide Web)
by Tim Berners-Lee at CERN in 1989
request–response in the client–server model
Resources located via URLs
Request Methods (aka Verbs):
- HEAD
- GET
- POST
- PUT/PATCH
- DELETE
HTTP
HTTP
So, REST?
Architectural style & set of conventions heavily based on the HTTP protocol to make easier to develop Web APIs :
REST
(Representational State Transfer)
- Client-server: Separation of concerns
- Stateless: Each request is isolated from each other
- Cacheable: Avoid double work and save bandwidth
- Uniform interface: Components based on Resources
Roy Fielding dissertation: http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
Resources
- Key abstraction/entity of information
- Resource identifiers: Usually some sort of ID
- Semantic: Self-descriptive
-
Support HTTP CRUD vebs/mehtods:
- GET
- PUT/PATCH
- POST
- DELETE
Example REST
Usage Lifecycle
Example
Example
Example
Example
Example
Example
Example
Example
Example
Example
Quick Demo
- Browser
- Postman / Insomnia
- cURL (command line)
- Code
Thanks!
REST APIs
By Benjamin Orozco (benoror)
REST APIs
REST APIs
- 1,068