know how backend apps workSeiji Villafranca
github.com/SeijiV13
seijivillafranca.com
github.com/SeijiV13
Senior Developer, Wypoon Technologies Netherlands
Microsoft MVP
Auth0 Ambassador
Community Lead, AngularPH,
Author
seijivillafranca.com
Endpoints
JSON
HTTP Requests (GET PUT
PATCH POST)
HTTP Response
Body
Queries
Mutation
Schema
Type
Fragment
let's go back!
year 2000, no standards are present for building APIs
Roy Fielding, invented REST
Client/server architecture, without any state or session preservation, resource representation caching, use of the HTTP protocol and its methods
The first ever REST API
The first ever REST API
{
"id": 1,
"name": "A green door",
"price": 12.50,
"tags": ["home", "green"]
}data of ebay is accessible making their products more visible
From ecommerce to social media
Flickr entered the scene, created its own REST API in 2004
Facebook and Twitter joined making the
use of API higher and higher
Companies using REST
100,000 ++ companies worldwide
number of publicly available APIs increases
set of architectural constraints, not a protocol or a standard
transfers data or state using endpoints
HTTP: JSON (Javascript Object Notation)
HTML
XLT
Plain Text
{
"name": "Seiji",
"place": "Netherlands",
"work": "Developer"
}A client-server architecture
Stateless client-server communication,
Cacheable data
layered system
Uniform interface
web development
iOS apps
IoT devices
Windows Phone apps
No specific client-side technology
Ruby
Languages are now for REST!
Python
C#
Java
JavaScript
REST is easy to implement
require 'net/http'
url = 'http://www.example.com/database/1191'
resp = Net::HTTP.get_response(URI.parse(url))
resp_text = resp.body
Ruby
REST is easy to implement
import urllib2
url = 'http://www.example.com/database/1191'
response = urllib2.urlopen(url).read() Python
REST is easy to implement
use LWP::Simple;
my $url = 'http://www.example.com/database/1191';
# sample request
my $response = get $url;
die 'Error getting $url' unless defined $response;
Perl
REST is easy to implement
$url = "http://www.example.com/database/1191";
$response = file_get_contents($url);
echo $response;
PHP
REST is easy to implement
req.open("GET", url, true);
req.send();
JavaScript
So, its easy to use and implement REST
But it can be improved!
Let's say, we have a user endpoint
get https://awesomeapi.com/users
Returns
{
"name": "Seiji",
"location": "Netherlands",
"position": "Developer",
"email": "villafrancasra@gmail.com"
}We only need to fetch the name and email
Need to create another api just to achieve this
get https://awesomeapi.com/users/simple
developed by
Think "Graphs", not "Endpoints"
Have a Single Source of Truth
Thin API Layer
query {
me {
name
nickname
profilePicture {
width
height
url
}
}
}
The structured way in which we make requests presents two types of operations: queries and mutations.
The structured way in which we make requests presents two types of operations: queries and mutations.
Queries that fetch data are synonymous to GET calls in REST
mutations signal that we’d like to invoke a change the in system, similar to REST’s POST or DELETE methods.
GraphQL is data source agnostic.
GraphQL is typically served over HTTP
type Book {
title: String
author: Author
}
type Author {
name: String
books: [Book]
}const resolvers = {
Query: {
movie: async (_, { id }, { dataSources }) => {
return dataSources.moviesAPI.getMovie(id);
},
mostViewedMovies: async (_, __, { dataSources }) => {
return dataSources.moviesAPI.getMostViewedMovies();
},
favorites: async (_, __, { dataSources }) => {
return dataSources.personalizationAPI.getFavorites();
},
},
};{
book(title: "A Song of Ice and Fire"){
id
}
}Tools, languages and frameworks
github.com/SeijiV13
seijivillafranca.com
fb.com/seiji.villafranca
Thank you
and happy coding!