Top Banner
for DESIGNING THE APIS an internal set of services
73

Designing the APIs for an internal set of services

Jul 07, 2015

Download

Technology

Alberto Leal

Desinging the APIs for an internal set of services
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Designing the APIs for an internal set of services

for

DESIGNING THE APIS

an internal set of services

Page 2: Designing the APIs for an internal set of services

albertoleal

[email protected]

Page 3: Designing the APIs for an internal set of services
Page 4: Designing the APIs for an internal set of services

https://github.com/globocom

Page 5: Designing the APIs for an internal set of services

forDESIGNING THE

an internal

APIS

set of services

Page 6: Designing the APIs for an internal set of services

what is an API ?

Page 7: Designing the APIs for an internal set of services

micro-services environment

Page 8: Designing the APIs for an internal set of services

"A concept where an application is

decomposed into small and loosely coupled

services, where each service has a single

responsibility, running in its own process.

Page 9: Designing the APIs for an internal set of services
Page 10: Designing the APIs for an internal set of services
Page 11: Designing the APIs for an internal set of services
Page 12: Designing the APIs for an internal set of services
Page 13: Designing the APIs for an internal set of services
Page 14: Designing the APIs for an internal set of services

ad$

A

Page 15: Designing the APIs for an internal set of services

Evolving a service

search

accounts

video

images

Page 16: Designing the APIs for an internal set of services

No restriction

Page 17: Designing the APIs for an internal set of services

Maintainable and

Stable

Page 18: Designing the APIs for an internal set of services

Replacement

Page 19: Designing the APIs for an internal set of services

test the services?

HO

W T

Odefine services contract?

manage deployment?

Page 20: Designing the APIs for an internal set of services

How do we get started with our

API?

Page 21: Designing the APIs for an internal set of services

API Modeling

Page 22: Designing the APIs for an internal set of services

API Modeling - Conceptual Model

Page 23: Designing the APIs for an internal set of services

purpose

Page 24: Designing the APIs for an internal set of services

audience

Page 25: Designing the APIs for an internal set of services

developer,developer, developer

Page 26: Designing the APIs for an internal set of services

Developer as a

Customer

API as a

Product

Page 27: Designing the APIs for an internal set of services

API Modeling - Ubiquitous Language

Page 28: Designing the APIs for an internal set of services

API Modeling

Page 29: Designing the APIs for an internal set of services

!Do not reinvent the wheel

HAL JSON API

JSON Schema

Page 30: Designing the APIs for an internal set of services

what makes a great API?

Page 31: Designing the APIs for an internal set of services

is

flexible and

simple to use

Page 32: Designing the APIs for an internal set of services

/cars?fields=name,model,year

/cars

Page 33: Designing the APIs for an internal set of services

uses

nouns instead of

verbs

Page 34: Designing the APIs for an internal set of services

/collection/<resource><?filters>

/cars/123?fields=name,model,year

Page 35: Designing the APIs for an internal set of services

/cars /cars?status=new /cars/123

/getAllCars /getAllNewCars /getCar/123

Page 36: Designing the APIs for an internal set of services

uses

HTTP Verbs to perform operations

on the elements

Page 37: Designing the APIs for an internal set of services

ResourcePOST

(create)GET

(read)PUT

(replace)PATCH

(update)DELETE (delete)

/cars new car list all carsnew car

or error

errordelete all

cars

/cars/123 error show car 123update car

or error

modify car or

error

delete car 123

Page 38: Designing the APIs for an internal set of services

returns meaningful errors

Page 39: Designing the APIs for an internal set of services
Page 40: Designing the APIs for an internal set of services

HTTP/1.1 400 Bad Request!!{ "errorCode" : 123, "moreInfo": “http://dev.api.com/errors/123" "errors": [ { "name": [ “can’t be blank" ] } ]}

use http status code

payload as verbose as possible

Page 41: Designing the APIs for an internal set of services

400 - 401 - 403 - 404 - 500

Bad Request Forbidden

Unauthorized Not Found

Internal Server Error

Page 42: Designing the APIs for an internal set of services

provides great support

Page 43: Designing the APIs for an internal set of services

Documentation

Page 44: Designing the APIs for an internal set of services
Page 45: Designing the APIs for an internal set of services

Documentation

Page 46: Designing the APIs for an internal set of services

Documentation Communication

Page 47: Designing the APIs for an internal set of services

CommunityDocumentation Communication

Page 48: Designing the APIs for an internal set of services

is secure

Page 49: Designing the APIs for an internal set of services

what about versioning?

Page 50: Designing the APIs for an internal set of services

application/vnd.example.com+json; version=1

application/vnd.example.com.v1+json;

Accept:

Page 51: Designing the APIs for an internal set of services

test the services?

HO

W T

Odefine services contract?

manage deployment?

Page 52: Designing the APIs for an internal set of services

ad$

A

Page 53: Designing the APIs for an internal set of services
Page 54: Designing the APIs for an internal set of services
Page 55: Designing the APIs for an internal set of services

contracts enable

service independence

Page 56: Designing the APIs for an internal set of services

but…

Page 57: Designing the APIs for an internal set of services

"A concept where an application is

decomposed into small and loosely coupled services, where each service has a single

responsibility, running in its own process.

Page 58: Designing the APIs for an internal set of services

Contracts can also

couple service providers

and

consumers

Page 59: Designing the APIs for an internal set of services
Page 60: Designing the APIs for an internal set of services
Page 61: Designing the APIs for an internal set of services
Page 62: Designing the APIs for an internal set of services

{ "title": "App", "type": "object", "properties": { "name": { "type": "string", "title": "Name" }, "uris": { "type": "array", "title":"URIs", "items": { "type": "string" } } }, "required": ["name"]}

required fields

Page 63: Designing the APIs for an internal set of services

{ "links": [ { "href": "https://domain/apps", "method": "POST", "rel": “create”, "schema": { "$ref": "https://domain/schemas/apps/new_app" } } … ]}

Page 64: Designing the APIs for an internal set of services

Consumer-Driven Contracts: A Service Evolution Pattern

http://martinfowler.com/articles/consumerDrivenContracts.html

Page 65: Designing the APIs for an internal set of services

test the services?

HO

W T

Odefine services contract?

manage deployment?

Page 66: Designing the APIs for an internal set of services

Deployment

imagessearch

Page 67: Designing the APIs for an internal set of services

Deployment

search

Page 68: Designing the APIs for an internal set of services

Deployment

Page 69: Designing the APIs for an internal set of services

test the services?

HO

W T

Odefine services contract?

manage deployment?

Page 70: Designing the APIs for an internal set of services
Page 71: Designing the APIs for an internal set of services

Contract Tests

IntegrationTests

Page 72: Designing the APIs for an internal set of services

be positive

Page 73: Designing the APIs for an internal set of services

thanks!@albertoleal

[email protected]