URI - These resources are manipulated using HTTP requests where the method (GET, POST, PUT, PATCH, DELETE) has specific meaning. - Discover resources, thanks to HATEOAS (Hypertext As The Engine Of Application State). 7
of posts GET /posts/12 - Retrieves a specific post GET /posts/12/comments - Retrieves comments GET /posts/12/comments/42/ - Retrieve specific comment POST /posts - Creates a new post PUT /posts/12 - Updates post #12 with payload provided PATCH /posts/12 - Partially updates post #12 DELETE /posts/12 - Deletes post #12 8
to version my API? - The URL way? /api/v1/post/12232 V2, v3, v4….?? - The Header way? GET /api/article/1234 HTTP/1.1 Accept: application/vnd.api.article+xml; version=1.0
Ad-hoc RPC with custom endpoint definitions. Time spent maintaining many versioned endpoint - REST requires many requests (many Roundtrips) - With REST, you request too much or too little data REST often turns into a maze of poorly-documented endpoints - Weak Typing and Poor Metadata 15
GraphQL directly to your backend or database. It’s an API layer, just like REST. GraphQL can be layered over multiple backends and databases, without the client being aware of where the data is coming from, just like REST. 19
by providing an intuitive and flexible syntax and system for describing their data requirements and interactions.” - GraphQL Specification https://facebook.github.io/graphql/ 20
types: Int, Float, String, Boolean, ID - Lists and Non-Null - Arguments: Every field on a GraphQL object type can have zero or more arguments - Enumeration types: a special kind of scalar that is restricted to a particular set of allowed values 33
(size: 250){ url } coverPhoto (size: 1200){ name, url } } fragment bodyFragment on User { location { name } friends } 39 fragment timelineFragment on User { ...headerFragment ...bodyFragment }
a function called the resolver which is provided by the GraphQL server developer When a field is executed, the corresponding resolver is called to produce the next value. 50
development: combining and Querying Data and Picking Your Payload - Specification: the spec determines the validity, Strongly Typed, hierachical with nested fields - An application layer. GraphQL is not a storage model or a database query language. - Auto documentation. Yeah!!! 61
opponents and making them see the light, but rather because its opponents eventually die out, and a new generation grows up that is familiar with it. — Max Planck Are RESTful APIs dead? 62