Designing RESTful Web APIs
WHAT IS REST
Shawn Wildermuth
MICROSOFT MVP, INSTRUCTOR AND FILMMAKER
@shawnwildermuth [Link]
Course
Overview What is this course?
- Helps you design Web APIs
- Agnostic to how implemented
- Understand REST’s role in APIs
- Introduce you to pragmatic design
What this course will teach you:
Course - How REST can be used to create APIs
Overview - Designing URI Endpoints
- Understand usage of verbs and nouns
- Why association APIs are important
- What role operational APIs take
- Why versioning APIs is so important
- To decide on securing your APIs
Course
Overview What you will need:
- Postman
• Operating System doesn’t matter
[Link]
Questions During the Course?
The History of Distributed APIs
Dawn of Object
Distributed Oriented Web-Based
Computing APIs APIs
Java
Queuing gRPC
RMI REST
Messaging CORBA GraphQL
XMLHTTP SOAP
RPC COM/
DCOM
2000
2020
2010
1990
1980
1970
Do You Really Need a Web API?
- Are you building a website?
- Are you building a Single Page App?
- Are you building a mobile app?
- If not, why are you doing it?
How Does HTTP Work?
POST
verb
Content Length: 11
headers
Stateless
content
Hello World
Request
Response
status
201code
headers
Content Type: text
content
Hello World
The Request Deconstructed
verb Action to perform on the server
headers • GET: Request Resource
• POST: Create Resource
• PUT: Update Resource
• PATCH: Update Partial Resource
content
• DELETE: Delete Resource
• More verbs…
The Request Deconstructed
verb Metadata about the request
headers • Content Type: The format of Content
• Content Length: Size of Content
• Authorization: Who’s making the call
• Accept: What type(s) can accept
content
• Cookies: Passenger data in the request
• More headers…
The Request Deconstructed
verb Content Concerning Request
headers • HTML, CSS, JavaScript, XML, JSON
• Content is not valid with some verbs
• Information to help fulfill request
• Binary and blobs common (e.g. .jpg)
content
The Response Deconstructed
status code Operation Status
headers • 100-199: Informational
• 200-299: Success
• 300-399: Redirection
• 400-499: Client Errors
content
• 500-599: Server Errors
The Response Deconstructed
verb Metadata about the response
headers • Content Type: The format of Content
• Content Length: Size of Content
• Expires: When to consider stale
• Cookies: Passenger data in the request
content
• More headers…
The Response Deconstructed
verb Content
headers • HTML, CSS, JavaScript, XML, JSON
• Binary and blobs common (e.g. .jpg)
• APIs often have their own types
content
Demo
HTTP in Action
REpresentational State Transfer*
- Concepts include:
• Separation of Client and Server
What is REST? • Server Requests are Stateless
• Cacheable Requests
• Uniform Interface
* Introduced by Roy Fielding's doctoral dissertation
Problems
- Too difficult to be qualified as "REST"
What is REST? - Dogma of REST vs. Pragmatism
• Structured architectural style
• The need to be productive
Demo
A Well Designed API
What We’ve Learned
HTTP is crucial to the way that APIs on the Web
Using REST is important, but be pragmatic about it
We’re designing a simple API to learn the basics
Next Up:
Designing a RESTful API