vs

know how backend apps work

Seiji Villafranca

github.com/SeijiV13

seijivillafranca.com

Seiji Villafranca

github.com/SeijiV13

Senior Developer, Wypoon Technologies Netherlands

Microsoft MVP

Auth0 Ambassador

Community Lead, AngularPH,

Author

seijivillafranca.com

Talks

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

Why use REST API?

REST API

set of architectural constraints, not a protocol or a standard

transfers data or state using endpoints

REST API

HTTP: JSON (Javascript Object Notation)

HTML

XLT

Plain Text

{
"name": "Seiji",
"place": "Netherlands",
"work": "Developer"
}

To be considered RESTful

A client-server architecture

Stateless client-server communication,

Cacheable data

layered system

Uniform interface

Simple overview of REST

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

Scaling models

query {
  me {
    name
    nickname
    profilePicture {
      width
      height
      url
    }
  }
}

The evolution phase

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.

Served over HTTP

GraphQL is typically served over HTTP

How does it works?

Design your GraphQL schema

type Book {
  title: String
  author: Author
}

type Author {
  name: String
  books: [Book]
}

Connect your resolvers to data sources

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();
    },
  },
};

Ask for exactly what you want

{
  book(title: "A Song of Ice and Fire"){
    id
  }
}

Tools, languages and frameworks

References

Hey I'm a Mentor!

github.com/SeijiV13

seijivillafranca.com

fb.com/seiji.villafranca

Thank you

and happy coding!

deck

By Seiji Ralph Villafranca