SlideShare a Scribd company logo
RESTful APIs
Presented by
Gregory M. Sohl
Designing APIs in the REST style with
examples in ASP.NET Web API
Assumptions
Basic understanding of HTTP
A little C#
A little ASP.NET
Background
Described in Roy Fielding dissertation in 2000
 Roots back to 1994
 Roy was a key contributor to HTTP and URI
Style of building APIs in distributed hypermedia systems
It is not
 Particular Framework or Technology
 Set of Standards
 Design Pattern
REST
REprestational State Transfer
 Transfer representations of resources in a particular State
Based on architectural style of WWW
Set of Constraints
Concepts
Resource
 Has a URI
 Conceptual mapping to one or more entities
URI
 Address to a resource, it’s primary key
Concepts
Representation
 Snapshot of a resource
 NOT the resource itself
Media Type
 A format for the representation
 Commonly JSON or XML – but no limits
Constraints
Client / Server
 Duh, it’s an interface from one thing to another
 Separation of Concerns
 Independent evolution
Stateless
 Each request is independent
 No stored context on the server
Constraints
Cache
 Responses must indicate
 Clients can choose to reuse
URIs
 Resources are identified by URIs
 Nouns instead of Verbs
 Multiple URIs can refer to the same resource
Constraints
Uniform Interface
 Resource based
HTTP verbs
POST, PUT, GET, DELETE, HEAD (for conditional GETs)
Generally ignore others, e.g. OPTIONS, PATCH and TRACE
 HTTP result codes
 Self-descriptive messages
 Generalized media types
Constraints
Layered System
 Client not necessarily talking directly to server
 Layers can only “see” each other
 Supports firewalls, proxies, etc.
Constraints
Code on Demand
 Server can download code – change client behavior
 Simplify client dev
 Optional constraint
URIs
URIs are resource based – nouns
 Verbs come from HTTP methods, GET, POST, PUT, DELETE
 Use slashes to indicate resource hierarchy
http://myapi.com/{resource}
http://myapi.com/{resource}/{id}/{document}
http://myapi.com/{resource}/{id}/{child resource}
URIs - Contrast to SOAP
SOAP methods
 GetCustomerList()
 AddNewCustomer()
 GetCustomerInfo()
 UpdateCustomer()
 DeleteCustomer()
URIs - Contrast to SOAP
REST Requests
/customers
GET - retrieve a list of customers
POST - create a new customer
/customers/{customer id}
GET - retrieve information about a customer
PUT - update a customer's information
DELETE - remove a customer
HTTP Verbs
HTTP Verbs
Verb Usage
GET read
HEAD like GET, but returns only headers
POST create and other uses
PUT update
DELETE remove
OPTIONS documentation
Building a RESTful API in .NET
ASP.NET - Great platform for REST style
Web API is specifically built for REST
 Many facilities and helpers built in
ASP.NET
Sites
MVC
Web
Forms
Web
Pages
SPA
Services
Web API SignalIR
HTTP Status Codes
1xx – Informational – seldom used
2xx – Success
3xx – Redirection, unchanged. Client should do
something different to complete the request.
4xx – Client action caused an error
5xx – Server error
Common HTTP Status Codes
200 OK – Request worked. Nothing to report
201 Created – Indicate new resource created
204 No Content – Used with conditional GETs
304 Not Modified – Used with
Common HTTP Status Codes
401 Unauthorized
404 Not found
500 Internal Server Error – Include details in body
503 Service Unavailable – Under maint, etc.
API Design
Art or Science?
Request Types
 Safe – No side effects
 Idempotent – Multiple requests have same effect
Method Safe Idempotent Cachable
GET Yes Yes Yes
POST No No No
PUT No Yes No
DELETE No Yes No
API Design
URIs
 Sensible names – using nouns
 Forward slashes for hierarchical relationships
 Use dashes in multi-word resource names for readability
 Consistent use of lowercase resource names
 Avoid file extensions
 Fine grained to support caching
API Design
Representation Formats
 Choose appropriate media types
JSON, XML, domain specific
Client indicates preference via Accept header
Caching
Responses indicate cachability of result
 Use Cache-Control header
 Use Expires header
 Generate ETag header
Unique for a resource version
 Using an Etag
 Use for GET & PUT
Caching – Why??
The internet caches
Some requests are expensive
Increase throughput
Related Info In Results
Favor links instead of related keys
User Group Demo
User groups and their city
API
 /usergroups
GET, POST
 /usergroups/{id}
GET, PUT, DELETE
 /usergroups/{id}/map
Documentation
Doc needs are not unlike for any API
 URIs
 Methods
 Parameters
 Data formats
 Response codes
 Samples
Why REST
HTTP is Ubiquitous
Lighter weight than SOAP
Caching Support
Acceptance
Scales well
Decoupled
Resources
Tutorial
 http://www.restapitutorial.com
Best Practices PDF
 http://www.restapitutorial.com/resources.html
Books
 Designing Evolvable Web APIs with ASP.NET
http://chimera.labs.oreilly.com/books/1234000001708/index.html
 RESTful Web Services Cookbook
http://www.amazon.com/RESTful-Web-Services-Cookbook-
Scalability/dp/0596801688
Resources
Courses
 http://www.pluralsight.com/courses/rest-fundamentals
Caching Management Library - Cache Cow
 http://www.hanselman.com/blog/NuGetPackageOfTheWeekAS
PNETWebAPICachingWithCacheCowAndCacheOutput.aspx

More Related Content

PPTX
RESTful Architecture
PPT
The Rest Architectural Style
PPTX
LESS - Template-based Syndication and Presentation of Linked Data for End-users
PDF
Rest http basics
PPTX
OData: A Standard API for Data Access
PPTX
Lightning Talk - Rest
PPTX
Restful Fundamentals
PPTX
OData Services
RESTful Architecture
The Rest Architectural Style
LESS - Template-based Syndication and Presentation of Linked Data for End-users
Rest http basics
OData: A Standard API for Data Access
Lightning Talk - Rest
Restful Fundamentals
OData Services

What's hot (20)

PPTX
JAX-RS 2.0 and OData
PPT
Separating REST Facts from Fallacies
PDF
A Look at OData
PDF
Learn REST in 18 Slides
PPTX
Open Data Protocol (OData)
PPTX
API Design Tour: Dell
KEY
Rest and the hypermedia constraint
PPTX
REST API Design & Development
PPTX
RESTEasy
PDF
Building social and RESTful frameworks
PPTX
WebLogic Developer Webcast 1: JPA 2.0
ODP
The Internet as Web Services: introduction to ReST
PPTX
JAX-RS. Developing RESTful APIs with Java
PDF
The never-ending REST API design debate
PPTX
PPTX
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
PPTX
Rest Webservice
PDF
ReSTful API Final
PPTX
REST API in Salesforce
PDF
Rest api testing
JAX-RS 2.0 and OData
Separating REST Facts from Fallacies
A Look at OData
Learn REST in 18 Slides
Open Data Protocol (OData)
API Design Tour: Dell
Rest and the hypermedia constraint
REST API Design & Development
RESTEasy
Building social and RESTful frameworks
WebLogic Developer Webcast 1: JPA 2.0
The Internet as Web Services: introduction to ReST
JAX-RS. Developing RESTful APIs with Java
The never-ending REST API design debate
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
Rest Webservice
ReSTful API Final
REST API in Salesforce
Rest api testing
Ad

Similar to RESTful APIs in .NET (20)

PPTX
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
PPTX
Rest APIs Training
PPTX
Rest WebAPI with OData
PDF
REST API Recommendations
PPTX
REST Methodologies
PPTX
A Deep Dive into RESTful API Design Part 2
PPTX
RESTful Services
PPT
RESTful SOA - 中科院暑期讲座
PDF
What is REST?
PPTX
REST & RESTful Web Services
PDF
Restful web-services
PPTX
Mini-Training: Let's have a rest
PDF
Writing RESTful Web Services
PDF
It is time for REST
PDF
Rest API Interview Questions PDF By ScholarHat
PPTX
ASP.NET Mvc 4 web api
PDF
What are restful web services?
PPTX
rest-api-basics.pptx
PPTX
Introduction to Web Services
PDF
Modern REST API design principles and rules.pdf
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
Rest APIs Training
Rest WebAPI with OData
REST API Recommendations
REST Methodologies
A Deep Dive into RESTful API Design Part 2
RESTful Services
RESTful SOA - 中科院暑期讲座
What is REST?
REST & RESTful Web Services
Restful web-services
Mini-Training: Let's have a rest
Writing RESTful Web Services
It is time for REST
Rest API Interview Questions PDF By ScholarHat
ASP.NET Mvc 4 web api
What are restful web services?
rest-api-basics.pptx
Introduction to Web Services
Modern REST API design principles and rules.pdf
Ad

More from Greg Sohl (11)

PPTX
A DSL for Your API
PPT
.NET Overview
PPTX
Cool .NET tools, techniques and libraries
PPTX
Net serialization
PPTX
A great clash of symbols
PPTX
What’s new in Visual Studio 2010 debugging
PPT
Automated Unit Testing and TDD
PPT
Analyzing .Net Application Memory Usage And Issues
PPT
Application Security Part 1 Threat Defense In Client Server Applications ...
PPT
.NET Recommended Resources
PPT
Object Oriented Programming In .Net
A DSL for Your API
.NET Overview
Cool .NET tools, techniques and libraries
Net serialization
A great clash of symbols
What’s new in Visual Studio 2010 debugging
Automated Unit Testing and TDD
Analyzing .Net Application Memory Usage And Issues
Application Security Part 1 Threat Defense In Client Server Applications ...
.NET Recommended Resources
Object Oriented Programming In .Net

Recently uploaded (20)

PPTX
CRUISE TICKETING SYSTEM | CRUISE RESERVATION SOFTWARE
PDF
System and Network Administraation Chapter 3
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
L1 - Introduction to python Backend.pptx
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
Mini project ppt template for panimalar Engineering college
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
medical staffing services at VALiNTRY
PPTX
ai tools demonstartion for schools and inter college
DOCX
The Five Best AI Cover Tools in 2025.docx
CRUISE TICKETING SYSTEM | CRUISE RESERVATION SOFTWARE
System and Network Administraation Chapter 3
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
L1 - Introduction to python Backend.pptx
A REACT POMODORO TIMER WEB APPLICATION.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Materi_Pemrograman_Komputer-Looping.pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Online Work Permit System for Fast Permit Processing
Mini project ppt template for panimalar Engineering college
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
How to Migrate SBCGlobal Email to Yahoo Easily
PTS Company Brochure 2025 (1).pdf.......
ManageIQ - Sprint 268 Review - Slide Deck
VVF-Customer-Presentation2025-Ver1.9.pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
medical staffing services at VALiNTRY
ai tools demonstartion for schools and inter college
The Five Best AI Cover Tools in 2025.docx

RESTful APIs in .NET

  • 1. RESTful APIs Presented by Gregory M. Sohl Designing APIs in the REST style with examples in ASP.NET Web API
  • 2. Assumptions Basic understanding of HTTP A little C# A little ASP.NET
  • 3. Background Described in Roy Fielding dissertation in 2000  Roots back to 1994  Roy was a key contributor to HTTP and URI Style of building APIs in distributed hypermedia systems It is not  Particular Framework or Technology  Set of Standards  Design Pattern
  • 4. REST REprestational State Transfer  Transfer representations of resources in a particular State Based on architectural style of WWW Set of Constraints
  • 5. Concepts Resource  Has a URI  Conceptual mapping to one or more entities URI  Address to a resource, it’s primary key
  • 6. Concepts Representation  Snapshot of a resource  NOT the resource itself Media Type  A format for the representation  Commonly JSON or XML – but no limits
  • 7. Constraints Client / Server  Duh, it’s an interface from one thing to another  Separation of Concerns  Independent evolution Stateless  Each request is independent  No stored context on the server
  • 8. Constraints Cache  Responses must indicate  Clients can choose to reuse URIs  Resources are identified by URIs  Nouns instead of Verbs  Multiple URIs can refer to the same resource
  • 9. Constraints Uniform Interface  Resource based HTTP verbs POST, PUT, GET, DELETE, HEAD (for conditional GETs) Generally ignore others, e.g. OPTIONS, PATCH and TRACE  HTTP result codes  Self-descriptive messages  Generalized media types
  • 10. Constraints Layered System  Client not necessarily talking directly to server  Layers can only “see” each other  Supports firewalls, proxies, etc.
  • 11. Constraints Code on Demand  Server can download code – change client behavior  Simplify client dev  Optional constraint
  • 12. URIs URIs are resource based – nouns  Verbs come from HTTP methods, GET, POST, PUT, DELETE  Use slashes to indicate resource hierarchy http://myapi.com/{resource} http://myapi.com/{resource}/{id}/{document} http://myapi.com/{resource}/{id}/{child resource}
  • 13. URIs - Contrast to SOAP SOAP methods  GetCustomerList()  AddNewCustomer()  GetCustomerInfo()  UpdateCustomer()  DeleteCustomer()
  • 14. URIs - Contrast to SOAP REST Requests /customers GET - retrieve a list of customers POST - create a new customer /customers/{customer id} GET - retrieve information about a customer PUT - update a customer's information DELETE - remove a customer
  • 15. HTTP Verbs HTTP Verbs Verb Usage GET read HEAD like GET, but returns only headers POST create and other uses PUT update DELETE remove OPTIONS documentation
  • 16. Building a RESTful API in .NET ASP.NET - Great platform for REST style Web API is specifically built for REST  Many facilities and helpers built in ASP.NET Sites MVC Web Forms Web Pages SPA Services Web API SignalIR
  • 17. HTTP Status Codes 1xx – Informational – seldom used 2xx – Success 3xx – Redirection, unchanged. Client should do something different to complete the request. 4xx – Client action caused an error 5xx – Server error
  • 18. Common HTTP Status Codes 200 OK – Request worked. Nothing to report 201 Created – Indicate new resource created 204 No Content – Used with conditional GETs 304 Not Modified – Used with
  • 19. Common HTTP Status Codes 401 Unauthorized 404 Not found 500 Internal Server Error – Include details in body 503 Service Unavailable – Under maint, etc.
  • 20. API Design Art or Science? Request Types  Safe – No side effects  Idempotent – Multiple requests have same effect Method Safe Idempotent Cachable GET Yes Yes Yes POST No No No PUT No Yes No DELETE No Yes No
  • 21. API Design URIs  Sensible names – using nouns  Forward slashes for hierarchical relationships  Use dashes in multi-word resource names for readability  Consistent use of lowercase resource names  Avoid file extensions  Fine grained to support caching
  • 22. API Design Representation Formats  Choose appropriate media types JSON, XML, domain specific Client indicates preference via Accept header
  • 23. Caching Responses indicate cachability of result  Use Cache-Control header  Use Expires header  Generate ETag header Unique for a resource version  Using an Etag  Use for GET & PUT
  • 24. Caching – Why?? The internet caches Some requests are expensive Increase throughput
  • 25. Related Info In Results Favor links instead of related keys
  • 26. User Group Demo User groups and their city API  /usergroups GET, POST  /usergroups/{id} GET, PUT, DELETE  /usergroups/{id}/map
  • 27. Documentation Doc needs are not unlike for any API  URIs  Methods  Parameters  Data formats  Response codes  Samples
  • 28. Why REST HTTP is Ubiquitous Lighter weight than SOAP Caching Support Acceptance Scales well Decoupled
  • 29. Resources Tutorial  http://www.restapitutorial.com Best Practices PDF  http://www.restapitutorial.com/resources.html Books  Designing Evolvable Web APIs with ASP.NET http://chimera.labs.oreilly.com/books/1234000001708/index.html  RESTful Web Services Cookbook http://www.amazon.com/RESTful-Web-Services-Cookbook- Scalability/dp/0596801688
  • 30. Resources Courses  http://www.pluralsight.com/courses/rest-fundamentals Caching Management Library - Cache Cow  http://www.hanselman.com/blog/NuGetPackageOfTheWeekAS PNETWebAPICachingWithCacheCowAndCacheOutput.aspx