Better RESTFul API – Best Practices

Slides:



Advertisements
Similar presentations
Pierre-Johan CHARTRE Java EE - JAX-RS - Pierre-Johan CHARTRE
Advertisements

REST Vs. SOAP.
REST Introduction 吴海生 博克软件(杭州)有限公司.
Building and using REST information services Rion Dooley.
OASIS OData Technical Committee. AGENDA Introduction OASIS OData Technical Committee OData Overview Work of the Technical Committee Q&A.
Hypertext Transfer PROTOCOL ----HTTP Sen Wang CSE5232 Network Programming.
Building RESTful Interfaces
Peoplesoft: Building and Consuming Web Services
06 | Implementing Web APIs Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek.
Hypertext Transport Protocol CS Dick Steflik.
 What is it ? What is it ?  URI,URN,URL URI,URN,URL  HTTP – methods HTTP – methods  HTTP Request Packets HTTP Request Packets  HTTP Request Headers.
CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.
Integrating Complementary Tools with PopMedNet TM 27 July 2015 Rich Schaaf
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control Maarten
Beyond the UI Using Tools to Improve Testing Jeremy Traylor
REST.  REST is an acronym standing for Representational State Transfer  A software architecture style for building scalable web services  Typically,
Python and REST Kevin Hibma. What is REST? Why REST? REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a.
Open Data Protocol * Han Wang 11/30/2012 *
Or, Hey can’t we just do it using HTTP for the envelope?
A Limited Definition of Web Services Paul Kopacz CIS* Service Oriented Architecture Instructor: Qusay H. Mahmoud, Ph.D. February.
DM_PPT_NP_v01 SESIP_0715_JR HDF Server HDF for the Web John Readey The HDF Group Champaign Illinois USA.
API Crash Course CWU Startup Club. OUTLINE What is an API? Why are API’s useful? What is HTTP? JSON? XML? What is a RESTful API? How do we consume an.
Advanced Web Technologies Lecture #4 By: Faraz Ahmed.
1 © Donald F. Ferguson, All rights reserved.Modern Internet Service Oriented Application Development – Lecture 2: REST Details and Patterns Some.
Representational State Transfer (REST). What is REST? Network Architectural style Overview: –Resources are defined and addressed –Transmits domain-specific.
RESTful Web Services What is RESTful?
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
Representational State Transfer COMP6017 Topics on Web Services Dr Nicholas Gibbins –
REST API Design. Application API API = Application Programming Interface APIs expose functionality of an application or service that exists independently.
National College of Science & Information Technology.
REST URI Merli Lall.
How HTTP Works Made by Manish Kushwaha.
API (Application Program Interface)
Hypertext Transfer Protocol
API Security Auditing Be Aware,Be Safe
WEB SERVICES.
REST: Web Services Abel Sanchez.
Node.js Express Web Services
Unit – 5 JAVA Web Services
C++ Tango REST API implementation
Advanced Web-based Systems | Misbhauddin
Hypertext Transfer Protocol
Hypertext Transport Protocol
What is REST API ? A REST (Representational State Transfer) Server simply provides access to resources and the REST client accesses and presents the.
Representational State Transfer
Beautiful REST + JSON APIs
API Documentation Guidelines
Ashish Pandit IT Architect, Middleware & Integration Services
Testing REST IPA using POSTMAN
WEB API.
Building Self Describing Web APIs
$, $$, $$$ API testing Edition
Testing RESTful Web APIs
JavaScript & jQuery AJAX.
A gentle introduction to RESTful APIs
EE 122: HyperText Transfer Protocol (HTTP)
While the audience is gathering. During breaks etc
REST APIs Maxwell Furman Department of MIS Fox School of Business
RESTful Web Services.
Building production-ready APIs with ASP.NET Core 2.2
Requests and Server Response Codes
Python and REST Kevin Hibma.
Week 05 Node.js Week 05
HTTP Hypertext Transfer Protocol
A gentle introduction to RESTful APIs
Web-Services and RESTful APIs
.NET Framework V3.5+ & RESTful web services
Chengyu Sun California State University, Los Angeles
REST API Design Borrowed heavily from:
Restful APIs 101 Laura
Presentation transcript:

Better RESTFul API – Best Practices SolarWinds Better RESTFul API – Best Practices

REST Architectural Style (not a protocol or design pattern) way of thinking & designing applications Resource oriented Separate API structure into logical resource x not a way to call methods over a network without the overhead of SOAP and WSDL

RESTful API An API is a developer's UI - just like any UI, it's important to ensure the user's experience is thought out carefully It represents a contract between you and those who Consume data Good desing is hard The easier your API is to consume, the more people that will consume it

How REST Api should be? Heterogeny (language, platform) Stateless Simple Intuitive Consistent Reliable Efficient Friendly to work with

https://cp.solarwinds.com/pages/viewpage.action?pageId=92131573 Coding Prepare environment https://cp.solarwinds.com/pages/viewpage.action?pageId=92131573

Use Verbs GET (SELECT): Retrieve a specific Resource from the Server, or a listing of Resources. POST (CREATE): Create a new Resource on the Server. PUT (UPDATE): Update a Resource on the Server, providing the entire Resource. PATCH (UPDATE): Update a Resource on the Server, providing only changed attributes. DELETE (DELETE): Remove a Resource from the Server. Here are two lesser known HTTP verbs: HEAD – Retrieve meta data about a Resource, such as a hash of the data or when it was last updated. OPTIONS – Retrieve information about what the Consumer is allowed to do with the Resource.

Endpoints - Use nouns but no verbs Never include actions / verbs as URL segments. Use nouns Do not use verbs: Resource GET read POST create PUT update DELETE /cars Returns a list of cars Create a new ticket Bulk update of cars Delete all cars /cars/711 Returns a specific car Method not allowed (405) Updates a specific ticket Deletes a specific ticket

Use plural nouns

Don’t expose Get (All) Allow paging sorting filtering field selection

Coding Proper implementation of GET

Use HTTP verb status code

Use HTTP status codes 200 – OK – Eyerything is working 201 – OK – New resource has been created 204 – OK – The resource was successfully deleted 304 – Not Modified – The client can use cached data 400 – Bad Request – The request was invalid or cannot be served. The exact error should be explained in the error payload. E.g. „The JSON is not valid“ 401 – Unauthorized – The request requires an user authentication 403 – Forbidden – The server understood the request, but is refusing it or the access is not allowed. 404 – Not found – There is no resource behind the URI. 422 – Unprocessable Entity – Should be used if the server cannot process the enitity, e.g. if an image cannot be formatted or mandatory fields are missing in the payload. 500 – Internal Server Error – API developers should avoid this error. If an error occurs in the global catch blog, the stracktrace should be logged and not returned as response.

Coding Return proper HTTP Code

Implement properly Patch (partial update) JSON Patch is a format (identified by the media type “application/json-patch+json”) for expressing a sequence of operations to apply to a target JSON document Array of objects Each represents a single Operation (specific task to perform https://www.janaks.com.np/implementing-jsonpatch-in-aspnet-core/

Coding Proper patch implementation

Use sub-resources We would like to get sub collection of a resource api/books/{bookid}/pictures We need to create additional endpoint Recomended to create separate controller

Coding Sub-resources

RPC-Style Calls Execusion based rather than resource based It’s not about data it’s about action /books/1/salesreport Let’s be pragmatic (sometimes we need somthing like this) Should be stateless Should be exceptional behaviour

Versioning Software evolves, API must be versioned Users/Customers rely on the API not changing But Requirements will change Support both new and old users Api Versioning != project versioning (Api Versioning is harder )

Write /expose documentation https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger