WEB API API API APPLICATION PROGRAMMING INTERFACE is

  • Slides: 18
Download presentation
WEB API

WEB API

API

API

API APPLICATION PROGRAMMING INTERFACE is a set of subroutine definitions, protocols, and tools for

API APPLICATION PROGRAMMING INTERFACE is a set of subroutine definitions, protocols, and tools for building application software. Purpose API make it easier for developers to use certain technologies in building applications.

API Documentation describing API: List of functions (endpoints) Calls (requests) Returns (responses) Implementations: Library

API Documentation describing API: List of functions (endpoints) Calls (requests) Returns (responses) Implementations: Library or framework that can be imported to develop an application OS interfaces between an app and OS (POSIX, Mac. OS API, Windows API) Remote APIs on remote servers

WEB (Remote) APIs A server-side programmatic interface allows the client application to communicate with

WEB (Remote) APIs A server-side programmatic interface allows the client application to communicate with the server Based on one or more publicly exposed endpoints and a defined request–response message system. Uses the network to provide its services

NET Protocols IP TCP HTTPS Address resolving and delivering packets Transmission Control between applications

NET Protocols IP TCP HTTPS Address resolving and delivering packets Transmission Control between applications over IP Content container Level (application protocol) Security Level URL: Protocol + address + port + path on server (URI) _https: //best. server. com: 8080/API/endpoints/cars? brand=FERRARI&color=RED

Web Services zhttps: //best. server. com: 8080/API/endpoints/cars? brand=FERRARI&color=RED Desktop Apps INTERNET Endpoint Mobile apps

Web Services zhttps: //best. server. com: 8080/API/endpoints/cars? brand=FERRARI&color=RED Desktop Apps INTERNET Endpoint Mobile apps Requests WEB SERVER Endpoint Other servers Response Endpoint s Endpoint Smart Teapot Web API Endpoint DB

SOAP vs REST Simple Object Access Protocol REpresentational State Transfer is a protocol is

SOAP vs REST Simple Object Access Protocol REpresentational State Transfer is a protocol is an architectural style uses services interfaces URL based services Works on top of any communication Protocol, even asynchronously (TCP HTTP FTP SMTP) Only XML Security and authorization are part of the protocol Fully described and provide information to users (WSDL) HTTP/HTTPS only JSON , XML, TEXT, HTML Authorization and security must be implemented separately Easy to implement

Principles of REST RESOURCES expose easily understood directory structure URIs. REPRESENTATIONS transfer JSON or

Principles of REST RESOURCES expose easily understood directory structure URIs. REPRESENTATIONS transfer JSON or XML to represent data objects and attributes. MESSAGES use HTTP methods explicitly (for example, GET, POST, PUT, and DELETE). STATELESS interactions store no client context on the server between requests. The client holds session state.

HTTP methods GET - Retrieve information. GET requests must be safe and idempotent, meaning

HTTP methods GET - Retrieve information. GET requests must be safe and idempotent, meaning regardless of how many times it repeats with the same parameters, the results are the same POST - Request that the resource at the URI do something with the provided entity PUT - Store an entity at a URI. PUT can create a new entity or update an existing one. PATCH - Update only the specified fields of an entity at a URI DELETE - Request that a resource be removed; however, the resource does not have to be removed immediately. HEAD, OPTIONS, TRACE and CONNECT

CRUD - HTTP REQUESTS IN REST HTTP Requests DB operations GET SELECT rows POST

CRUD - HTTP REQUESTS IN REST HTTP Requests DB operations GET SELECT rows POST INSERT new row PUT UPDATE row DELETE row PATCH UPDATE certain field

HTTP request status codes indicate the result of the HTTP request. 1 XX -

HTTP request status codes indicate the result of the HTTP request. 1 XX - informational 2 XX – success (200 -OK, 201 – Created, 204 - No Content) 3 XX - redirection 4 XX - client error (400 -Bad Request, 401 Unauthorized, 403 - Forbidden, 404 - PNF) 5 XX - server error

Request Structure A request line GET /images/logo. png HTTP/1. 1 Request header fields Accept-Language:

Request Structure A request line GET /images/logo. png HTTP/1. 1 Request header fields Accept-Language: en Content-Type: text/html Cookie: <cookie-list> An empty line. An optional message body. JSON, TEXT, XML

Response Structure A status line which includes the status code and reason message HTTP/1.

Response Structure A status line which includes the status code and reason message HTTP/1. 1 200 OK Response header fields Content-Type: text/html Allow: GET, HEAD. An empty line. An optional message body JSON, TEXT, XML