SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
usable
                              REST APIs
{"links":[
 {"rel":"author",    "uri":"http://javier-ramirez.com"},
 {"rel":"work",      "uri":"http://aspgems.com"},
 {"rel":"blog",      "uri":"http://formatinternet.com"},
 {"rel":"twittEr",   "uri":"http//twitter.com/supercoco9"}
]}
1996
1995
1996
1994
2001
1999
2004
Web usability is an
approach to make web sites
    easy to use for an
  end-user, without the
   requirement that any
   specialized training be
         undertaken.[
Learnability
EfficIeNcy
MemorabiliTy
Errors
SatisfActiOn
I want YOU
  to make
a (REST) API
REST in a
                       nutshell

client server stateless layered and cacheable
Resources
     Resource Identifiers
     Resource metadata
Uniform interface
     operations
     Representations
     Representation metadata
Optionally: code on demand
making a REST API
  with Rails?



   easy
BASIC
    WEB/api
functionality
   IN RAILS
Cohesion

pleasE
separation of concerns
SUCCESS consistently




       fail consistently
expose
   ONLY
 WHAT IS
 Strictly
necessary
resources are not models
Aggregation/
 composition




               Multiple
           representations
Multiple consumers
All your
 FORMAT
are belong
 to us
> curl -d "login=ficticious_user@invoicefu.com&password=keepdreaming" https://invoicefu.com/api/session?format=json

{"user":{"id":108,"name":"Nicolas Carroll","email":"ficticioususer@invoicefu.com","locale":"en","twitter_nickname
":null,"facebook_uid":null,"facebook_nickname":null,"api_key":"dbd349b30b6d9fde97b01b827e6be5ed1e4fbe72","links":
[{"rel":"session","uri":"https://invoicefu.com/api/session","methods":"GET,POST,DESTROY"},"rel":"account","uri":"
https://invoicefu.com/api/accounts/108-cole-mertz-fake","methods":"GET,PUT"},"rel":"clients","uri":"https://invoi
cefu.com/api/accounts/108-cole-mertz-fake/clients","methods":"GET,POST"},{"rel":"new_client","uri":"https://invoi
cefu.com/api/accounts/108-cole-mertz-fake/clients/new","methods":"GET"},{"rel":"invoices","uri":"https://invoicef
u.com/api/accounts/108-cole-mertz-fake/invoices","methods":"GET,POST"},{"rel":"new_invoice","uri":"https://invoic
efu.com/api/accounts/108-cole-mertz-fake/invoices/new","methods":"GET"},{"rel":"proformas","uri":"https://invoice
fu.com/api/accounts/108-cole-mertz-fake/proformas","methods":"GET,POST"},{"rel":"new_proforma","uri":"https://inv
oicefu.com/api/accounts/108-cole-mertz-fake/proformas/new","methods":"GET"}]}}
can I haz cat readable anzwa
>   curl -d "login=ficticioususer@invoicefu.com&password=yeahyeah" "https://invoicefu.com/api/session?&format=xml

<?xml version="1.0" encoding="UTF-8"?>
<user>
  <id>108</id>
  <name>Nicolas Carroll</name>
  <email>user000007@invoicefu.com</email>
  <locale>en</locale>
  <twitter-nickname nil="true"></twitter-nickname>
  <facebook-uid nil="true"></facebook-uid>
  <facebook-nickname nil="true"></facebook-nickname>
  <api-key>dbd349b30b6d9fde97b01b827e6be5ed1e4fbe72</api-key>
  <links>
    <link>
       <rel>session</rel>
       <uri>https://invoicefu-localhost.com/api/session</uri>
       <methods>GET,POST,DESTROY</methods>
    </link>
    <link>
       <rel>account</rel>
       <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake</uri>
       <methods>GET,PUT</methods>
    </link>
    <link>
       <rel>clients</rel>
       <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/clients</uri>
       <methods>GET,POST</methods>
    </link>
    <link>
       <rel>new_client</rel>
       <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/clients/new</uri>
       <methods>GET</methods>
    </link>
    (…)

  </links>
</user>
Accept: application/vnd.aspgems.invoicefu.v1.xml

   THE
 ACCEPT
 HEADER


HTTP/REST Standard        Not everyone          Less obvious
Unambiguous               supports headers      Harder to use
Resources !=              or custom types       Non standard content-
Representations                                 types
Version as you need it                          Skips HTTP server logs
templates
        for new
       resources
> curl "https://invoicefu.com/api/v1/accounts/108-cole-mertz-fake/invoices/new?
api_key=ddd349b30b6d9fde97b01b827e6be5ed1e4fbe72&format=json"

{"invoice":{"number":"2011/30","issued_on":"2011-12-
12","proforma_id":null,"notes":null,"footer":null,"locale":"en","currency_code":"USD","currency_sym
bol":"$","ac_name":"Cole-Mertz#FAKE","ac_company_number_name":"Company
number","ac_company_number":"25465828K","ac_tax_number_name":"VAT
Number","ac_tax_number":"ES25464828k","ac_address":"234 brecknock
road","ac_city":"london","ac_province":null,"ac_postal_code":"n18 5bq","ac_country_name":"United
Kingdom","cl_email":null,"cl_name":null,"cl_company_number_name":null,"cl_company_number":null,"cl_
tax_number_name":null,"cl_tax_number":null,"cl_address":null,"cl_city":null,"cl_province":null,"cl_
postal_code":null,"cl_country_name":null,"invoice_lines":[],"discount_percent":null,"tax_lines":
[{"name":"TVA","signed_percent":"19.6"}],"paid":"0.0","links":
[{"rel":"payments","uri":"https://invoicefu.com/api/accounts/108-cole-mertz-
fake/invoices//payments","methods":"POST"},
{"rel":"account","uri":"https://invoicefu.com/api/accounts/108-cole-mertz-
fake","methods":"GET,PUT"},{"rel":"client","uri":null,"methods":"GET,PUT,DELETE"},
{"rel":"proforma","uri":null,"methods":"GET,PUT,DELETE"},{"rel":"pdf","uri":null,"methods":"GET"},
{"rel":"invoices","uri":"https://invoicefu.com/api/accounts/108-cole-mertz-
fake/invoices","methods":"GET,POST"}]}}j
EASy
  To
 FIND
> curl https://invoicefu.com?format=xml   (or   curl -H "Accept: application/xml" "https://invoicefu.com")

<?xml version="1.0" encoding="UTF-8"?>
<invoicefu>
  <links>
    <link>
      <rel>session</rel>
      <uri>https://invoicefu.com/api/session</uri>
      <methods>POST.DELETE</methods>
    </link>
    <link>
      <rel>countries</rel>
      <uri>https://invoicefu.com/api/countries</uri>
      <methods>GET</methods>
    </link>
    <link>
      <rel>api_v1</rel>
      <uri>https://invoicefu.com/api/session?api_version=1</uri>
      <methods>POST.DELETE</methods>
    </link>
    <link>
      <rel>xml_representation</rel>
      <uri>https://invoicefu.com/api/session?format=xml</uri>
      <methods>POST.DELETE</methods>
    </link>
    <link>
      <rel>json_representation</rel>
      <uri>https://invoicefu.com/api/session?format=json</uri>
      <methods>POST.DELETE</methods>
    </link>
    <link>
      <rel>strict_parameters</rel>
      <uri>https://invoicefu.com/api/session?strict=true</uri>
      <methods>POST.DELETE</methods>
    </link>
  </links>
>   curl -d "login=ficticioususer@invoicefu.com&password=yeahyeah" "https://invoicefu.com/api/session?&format=xml

<?xml version="1.0" encoding="UTF-8"?>
<user>
  <id>108</id>
  <name>Nicolas Carroll</name>
  <email>user000007@invoicefu.com</email>
  <locale>en</locale>
  <twitter-nickname nil="true"></twitter-nickname>
  <facebook-uid nil="true"></facebook-uid>
  <facebook-nickname nil="true"></facebook-nickname>
  <api-key>dbd349b30b6d9fde97b01b827e6be5ed1e4fbe72</api-key>
  <links>
    <link>
       <rel>session</rel>
       <uri>https://invoicefu-localhost.com/api/session</uri>
       <methods>GET,POST,DESTROY</methods>
    </link>
    <link>
       <rel>account</rel>
       <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake</uri>
       <methods>GET,PUT</methods>
    </link>
    <link>
       <rel>clients</rel>
       <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/clients</uri>
       <methods>GET,POST</methods>
    </link>
    <link>
       <rel>new_client</rel>
       <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/clients/new</uri>
       <methods>GET</methods>
    </link>
    <link>
       <rel>invoices</rel>
       <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/invoices</uri>
       <methods>GET,POST</methods>
    </link>

     (…)

  </links>
</user>
BASIC ACCESS AUTHENTICATION
 authenticate_or_request_with_http_basic do |login, password|
   User.find_by_login_and_password login, password
 end
User and password must be passed every time




TOKEN
Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join )
User.find_by_login_and_api_key( params[:login], params[:api_key] )
Client can send it as a parameter or as a header




OAUTH
Depends on third party libraries
Requires initial registration of client and more integration
Performance
params &
 debug
> curl "https://invoicefu.com/api/accounts/108-cole-mertz-fake/invoices/new?
api_key=ddd349b30b6d9fde97b01b827e6be5ed1e4fbe72&format=xml&debug=1"

<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>extra params found: debug. Allowed params are:
account_id,client_id,invoice_id,proforma_id</error>
</errors>


> curl "https://invoicefu.com/api/accounts/108-cole-mertz-fake/invoices/new?
api_key=ddd349b30b6d9fde97b01b827e6be5ed1e4fbe72&format=xml&debug=1&strict=false"
<?xml version="1.0" encoding="UTF-8"?>
<invoice>
  <number>2011/30</number>
  <issued-on>2011-12-11</issued-on>
  <proforma-id nil="true"></proforma-id>
    (...)

 <links>
   (...)

    <link>
      <rel>invoices</rel>
      <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/invoices</uri>
      <methods>GET,POST</methods>
    </link>
  </links>
</invoice>
helping
     your users

      WADL
json schema
{                                                <?xml version="1.0"?>
     "name":"Product",                           <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     "properties":{                               xsi:schemaLocation="http://wadl.dev.java.net/2009/02 wadl.xsd"
        "id":{                                    xmlns:tns="urn:yahoo:yn"
           "type":"number",                       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                                                  xmlns:yn="urn:yahoo:yn"
           "description":"Product identifier",
                                                  xmlns:ya="urn:yahoo:api"
           "required":true                        xmlns="http://wadl.dev.java.net/2009/02">
        },                                         <grammars>
        "name":{                                     <include
           "description":"Name of the                  href="NewsSearchResponse.xsd"/>
product",                                            <include
           "type":"string",                            href="Error.xsd"/>
           "required":true                         </grammars>
        },
        "price":{                                  <resources base="http://api.search.yahoo.com/NewsSearchService/V1/">
                                                     <resource path="newsSearch">
           "required":true,
                                                       <method name="GET" id="search">
           "type": "number",                             <request>
           "minimum":0,                                    <param name="appid" type="xsd:string"
           "required":true                                   style="query" required="true"/> 22
        },                                                 <param name="type" style="query" default="all">
        "tags":{                                             <option value="all"/>
           "type":"array",                                   <option value="any"/>
           "items":{                                         <option value="phrase"/>
             "type":"string"                               </param>
           }                                               <param name="start" style="query" type="xsd:int" default="1"/>
                                                           <param name="language" style="query" type="xsd:string"/>
        }
                                                         </request>
     },                                                  <response status="200">
     "links":[                                             <representation mediaType="application/xml"
        {                                                    element="yn:ResultSet"/>
           "rel":"full",                                 </response>
           "href":"{id}"                                 <response status="400">
        },                                                 <representation mediaType="application/xml"
        {                                                    element="ya:Error"/>
           "rel":"comments",                             </response>
           "href":"comments/?id={id}"                  </method>
                                                     </resource>
        }
                                                   </resources>
     ]
   }                                             </application>
tools
curl
Hurl
Httparty
restclient
apigee
Usable Rest APIs by Javier Ramirez at London Ruby User Group
Usable Rest APIs by Javier Ramirez at London Ruby User Group

Más contenido relacionado

Destacado

Finanzierung startup startimpuls bern jan 2013
Finanzierung startup startimpuls bern jan 2013Finanzierung startup startimpuls bern jan 2013
Finanzierung startup startimpuls bern jan 2013Nicolas Berg
 
120525 af internship invitation
120525 af internship invitation120525 af internship invitation
120525 af internship invitationDenish Anugra
 
Avaluacio multimedia
Avaluacio multimediaAvaluacio multimedia
Avaluacio multimediaMiriam Robles
 
Co working lloret by esther
Co working lloret   by estherCo working lloret   by esther
Co working lloret by estherCoWorking Lloret
 
El abuso sexual infantil
El abuso sexual infantilEl abuso sexual infantil
El abuso sexual infantilAreli Balboa
 
El Big Data y Business Intelligence en mi empresa: ¿de qué me sirve?
El Big Data y Business Intelligence en mi empresa: ¿de qué me sirve?El Big Data y Business Intelligence en mi empresa: ¿de qué me sirve?
El Big Data y Business Intelligence en mi empresa: ¿de qué me sirve?Alex Rayón Jerez
 
Trucos publicitarios colores
Trucos publicitarios coloresTrucos publicitarios colores
Trucos publicitarios coloresJair Reséndiz
 
Motor and gear engineering specialized in design, engineering and manufactu...
Motor and gear engineering   specialized in design, engineering and manufactu...Motor and gear engineering   specialized in design, engineering and manufactu...
Motor and gear engineering specialized in design, engineering and manufactu...Motor & Gear Engineering, Inc.
 
Chapter 3 (brand positioning)
Chapter 3 (brand positioning)Chapter 3 (brand positioning)
Chapter 3 (brand positioning)Jawad Chaudhry
 
Demostración de guiones periodísticos televisivos.
Demostración de guiones periodísticos televisivos.Demostración de guiones periodísticos televisivos.
Demostración de guiones periodísticos televisivos.Jibél Rojas
 
Virtual desktop infrastructure
Virtual desktop infrastructureVirtual desktop infrastructure
Virtual desktop infrastructureGokulan Subramani
 
2012 World Footwear Yearbook
2012 World Footwear Yearbook2012 World Footwear Yearbook
2012 World Footwear YearbookMelih ÖZCANLI
 

Destacado (20)

Edificio vicson margarita danies
Edificio vicson   margarita daniesEdificio vicson   margarita danies
Edificio vicson margarita danies
 
Finanzierung startup startimpuls bern jan 2013
Finanzierung startup startimpuls bern jan 2013Finanzierung startup startimpuls bern jan 2013
Finanzierung startup startimpuls bern jan 2013
 
120525 af internship invitation
120525 af internship invitation120525 af internship invitation
120525 af internship invitation
 
Avaluacio multimedia
Avaluacio multimediaAvaluacio multimedia
Avaluacio multimedia
 
Mil millones de bocas
Mil millones de bocasMil millones de bocas
Mil millones de bocas
 
Co working lloret by esther
Co working lloret   by estherCo working lloret   by esther
Co working lloret by esther
 
Resume revamp
Resume revampResume revamp
Resume revamp
 
Normas
NormasNormas
Normas
 
El abuso sexual infantil
El abuso sexual infantilEl abuso sexual infantil
El abuso sexual infantil
 
El Big Data y Business Intelligence en mi empresa: ¿de qué me sirve?
El Big Data y Business Intelligence en mi empresa: ¿de qué me sirve?El Big Data y Business Intelligence en mi empresa: ¿de qué me sirve?
El Big Data y Business Intelligence en mi empresa: ¿de qué me sirve?
 
Trucos publicitarios colores
Trucos publicitarios coloresTrucos publicitarios colores
Trucos publicitarios colores
 
Cmc origen sistema solar
Cmc origen sistema solarCmc origen sistema solar
Cmc origen sistema solar
 
Unidad3 valoraciones perito
Unidad3 valoraciones peritoUnidad3 valoraciones perito
Unidad3 valoraciones perito
 
Motor and gear engineering specialized in design, engineering and manufactu...
Motor and gear engineering   specialized in design, engineering and manufactu...Motor and gear engineering   specialized in design, engineering and manufactu...
Motor and gear engineering specialized in design, engineering and manufactu...
 
Chapter 3 (brand positioning)
Chapter 3 (brand positioning)Chapter 3 (brand positioning)
Chapter 3 (brand positioning)
 
Demostración de guiones periodísticos televisivos.
Demostración de guiones periodísticos televisivos.Demostración de guiones periodísticos televisivos.
Demostración de guiones periodísticos televisivos.
 
Virtual desktop infrastructure
Virtual desktop infrastructureVirtual desktop infrastructure
Virtual desktop infrastructure
 
2012 World Footwear Yearbook
2012 World Footwear Yearbook2012 World Footwear Yearbook
2012 World Footwear Yearbook
 
El TDAH en jóvenes y adultos. Por Javier Quintero
El TDAH en jóvenes y adultos. Por Javier QuinteroEl TDAH en jóvenes y adultos. Por Javier Quintero
El TDAH en jóvenes y adultos. Por Javier Quintero
 
Empresa telmex
Empresa telmexEmpresa telmex
Empresa telmex
 

Más de javier ramirez

¿Se puede vivir del open source? T3chfest
¿Se puede vivir del open source? T3chfest¿Se puede vivir del open source? T3chfest
¿Se puede vivir del open source? T3chfestjavier ramirez
 
QuestDB: The building blocks of a fast open-source time-series database
QuestDB: The building blocks of a fast open-source time-series databaseQuestDB: The building blocks of a fast open-source time-series database
QuestDB: The building blocks of a fast open-source time-series databasejavier ramirez
 
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...javier ramirez
 
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...javier ramirez
 
Deduplicating and analysing time-series data with Apache Beam and QuestDB
Deduplicating and analysing time-series data with Apache Beam and QuestDBDeduplicating and analysing time-series data with Apache Beam and QuestDB
Deduplicating and analysing time-series data with Apache Beam and QuestDBjavier ramirez
 
Your Database Cannot Do this (well)
Your Database Cannot Do this (well)Your Database Cannot Do this (well)
Your Database Cannot Do this (well)javier ramirez
 
Your Timestamps Deserve Better than a Generic Database
Your Timestamps Deserve Better than a Generic DatabaseYour Timestamps Deserve Better than a Generic Database
Your Timestamps Deserve Better than a Generic Databasejavier ramirez
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...javier ramirez
 
QuestDB-Community-Call-20220728
QuestDB-Community-Call-20220728QuestDB-Community-Call-20220728
QuestDB-Community-Call-20220728javier ramirez
 
Processing and analysing streaming data with Python. Pycon Italy 2022
Processing and analysing streaming  data with Python. Pycon Italy 2022Processing and analysing streaming  data with Python. Pycon Italy 2022
Processing and analysing streaming data with Python. Pycon Italy 2022javier ramirez
 
QuestDB: ingesting a million time series per second on a single instance. Big...
QuestDB: ingesting a million time series per second on a single instance. Big...QuestDB: ingesting a million time series per second on a single instance. Big...
QuestDB: ingesting a million time series per second on a single instance. Big...javier ramirez
 
Servicios e infraestructura de AWS y la próxima región en Aragón
Servicios e infraestructura de AWS y la próxima región en AragónServicios e infraestructura de AWS y la próxima región en Aragón
Servicios e infraestructura de AWS y la próxima región en Aragónjavier ramirez
 
Primeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverlessPrimeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverlessjavier ramirez
 
How AWS is reinventing the cloud
How AWS is reinventing the cloudHow AWS is reinventing the cloud
How AWS is reinventing the cloudjavier ramirez
 
Analitica de datos en tiempo real con Apache Flink y Apache BEAM
Analitica de datos en tiempo real con Apache Flink y Apache BEAMAnalitica de datos en tiempo real con Apache Flink y Apache BEAM
Analitica de datos en tiempo real con Apache Flink y Apache BEAMjavier ramirez
 
Getting started with streaming analytics
Getting started with streaming analyticsGetting started with streaming analytics
Getting started with streaming analyticsjavier ramirez
 
Getting started with streaming analytics: Setting up a pipeline
Getting started with streaming analytics: Setting up a pipelineGetting started with streaming analytics: Setting up a pipeline
Getting started with streaming analytics: Setting up a pipelinejavier ramirez
 
Getting started with streaming analytics: Deep Dive
Getting started with streaming analytics: Deep DiveGetting started with streaming analytics: Deep Dive
Getting started with streaming analytics: Deep Divejavier ramirez
 
Getting started with streaming analytics: streaming basics (1 of 3)
Getting started with streaming analytics: streaming basics (1 of 3)Getting started with streaming analytics: streaming basics (1 of 3)
Getting started with streaming analytics: streaming basics (1 of 3)javier ramirez
 
Monitorización de seguridad y detección de amenazas con AWS
Monitorización de seguridad y detección de amenazas con AWSMonitorización de seguridad y detección de amenazas con AWS
Monitorización de seguridad y detección de amenazas con AWSjavier ramirez
 

Más de javier ramirez (20)

¿Se puede vivir del open source? T3chfest
¿Se puede vivir del open source? T3chfest¿Se puede vivir del open source? T3chfest
¿Se puede vivir del open source? T3chfest
 
QuestDB: The building blocks of a fast open-source time-series database
QuestDB: The building blocks of a fast open-source time-series databaseQuestDB: The building blocks of a fast open-source time-series database
QuestDB: The building blocks of a fast open-source time-series database
 
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
 
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
 
Deduplicating and analysing time-series data with Apache Beam and QuestDB
Deduplicating and analysing time-series data with Apache Beam and QuestDBDeduplicating and analysing time-series data with Apache Beam and QuestDB
Deduplicating and analysing time-series data with Apache Beam and QuestDB
 
Your Database Cannot Do this (well)
Your Database Cannot Do this (well)Your Database Cannot Do this (well)
Your Database Cannot Do this (well)
 
Your Timestamps Deserve Better than a Generic Database
Your Timestamps Deserve Better than a Generic DatabaseYour Timestamps Deserve Better than a Generic Database
Your Timestamps Deserve Better than a Generic Database
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
 
QuestDB-Community-Call-20220728
QuestDB-Community-Call-20220728QuestDB-Community-Call-20220728
QuestDB-Community-Call-20220728
 
Processing and analysing streaming data with Python. Pycon Italy 2022
Processing and analysing streaming  data with Python. Pycon Italy 2022Processing and analysing streaming  data with Python. Pycon Italy 2022
Processing and analysing streaming data with Python. Pycon Italy 2022
 
QuestDB: ingesting a million time series per second on a single instance. Big...
QuestDB: ingesting a million time series per second on a single instance. Big...QuestDB: ingesting a million time series per second on a single instance. Big...
QuestDB: ingesting a million time series per second on a single instance. Big...
 
Servicios e infraestructura de AWS y la próxima región en Aragón
Servicios e infraestructura de AWS y la próxima región en AragónServicios e infraestructura de AWS y la próxima región en Aragón
Servicios e infraestructura de AWS y la próxima región en Aragón
 
Primeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverlessPrimeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverless
 
How AWS is reinventing the cloud
How AWS is reinventing the cloudHow AWS is reinventing the cloud
How AWS is reinventing the cloud
 
Analitica de datos en tiempo real con Apache Flink y Apache BEAM
Analitica de datos en tiempo real con Apache Flink y Apache BEAMAnalitica de datos en tiempo real con Apache Flink y Apache BEAM
Analitica de datos en tiempo real con Apache Flink y Apache BEAM
 
Getting started with streaming analytics
Getting started with streaming analyticsGetting started with streaming analytics
Getting started with streaming analytics
 
Getting started with streaming analytics: Setting up a pipeline
Getting started with streaming analytics: Setting up a pipelineGetting started with streaming analytics: Setting up a pipeline
Getting started with streaming analytics: Setting up a pipeline
 
Getting started with streaming analytics: Deep Dive
Getting started with streaming analytics: Deep DiveGetting started with streaming analytics: Deep Dive
Getting started with streaming analytics: Deep Dive
 
Getting started with streaming analytics: streaming basics (1 of 3)
Getting started with streaming analytics: streaming basics (1 of 3)Getting started with streaming analytics: streaming basics (1 of 3)
Getting started with streaming analytics: streaming basics (1 of 3)
 
Monitorización de seguridad y detección de amenazas con AWS
Monitorización de seguridad y detección de amenazas con AWSMonitorización de seguridad y detección de amenazas con AWS
Monitorización de seguridad y detección de amenazas con AWS
 

Último

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Último (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Usable Rest APIs by Javier Ramirez at London Ruby User Group

  • 1. usable REST APIs {"links":[ {"rel":"author", "uri":"http://javier-ramirez.com"}, {"rel":"work", "uri":"http://aspgems.com"}, {"rel":"blog", "uri":"http://formatinternet.com"}, {"rel":"twittEr", "uri":"http//twitter.com/supercoco9"} ]}
  • 9. Web usability is an approach to make web sites easy to use for an end-user, without the requirement that any specialized training be undertaken.[
  • 11. I want YOU to make a (REST) API
  • 12. REST in a nutshell client server stateless layered and cacheable Resources Resource Identifiers Resource metadata Uniform interface operations Representations Representation metadata Optionally: code on demand
  • 13. making a REST API with Rails? easy
  • 14. BASIC WEB/api functionality IN RAILS
  • 17. SUCCESS consistently fail consistently
  • 18. expose ONLY WHAT IS Strictly necessary
  • 20. Aggregation/ composition Multiple representations
  • 22. All your FORMAT are belong to us
  • 23. > curl -d "login=ficticious_user@invoicefu.com&password=keepdreaming" https://invoicefu.com/api/session?format=json {"user":{"id":108,"name":"Nicolas Carroll","email":"ficticioususer@invoicefu.com","locale":"en","twitter_nickname ":null,"facebook_uid":null,"facebook_nickname":null,"api_key":"dbd349b30b6d9fde97b01b827e6be5ed1e4fbe72","links": [{"rel":"session","uri":"https://invoicefu.com/api/session","methods":"GET,POST,DESTROY"},"rel":"account","uri":" https://invoicefu.com/api/accounts/108-cole-mertz-fake","methods":"GET,PUT"},"rel":"clients","uri":"https://invoi cefu.com/api/accounts/108-cole-mertz-fake/clients","methods":"GET,POST"},{"rel":"new_client","uri":"https://invoi cefu.com/api/accounts/108-cole-mertz-fake/clients/new","methods":"GET"},{"rel":"invoices","uri":"https://invoicef u.com/api/accounts/108-cole-mertz-fake/invoices","methods":"GET,POST"},{"rel":"new_invoice","uri":"https://invoic efu.com/api/accounts/108-cole-mertz-fake/invoices/new","methods":"GET"},{"rel":"proformas","uri":"https://invoice fu.com/api/accounts/108-cole-mertz-fake/proformas","methods":"GET,POST"},{"rel":"new_proforma","uri":"https://inv oicefu.com/api/accounts/108-cole-mertz-fake/proformas/new","methods":"GET"}]}}
  • 24. can I haz cat readable anzwa > curl -d "login=ficticioususer@invoicefu.com&password=yeahyeah" "https://invoicefu.com/api/session?&format=xml <?xml version="1.0" encoding="UTF-8"?> <user> <id>108</id> <name>Nicolas Carroll</name> <email>user000007@invoicefu.com</email> <locale>en</locale> <twitter-nickname nil="true"></twitter-nickname> <facebook-uid nil="true"></facebook-uid> <facebook-nickname nil="true"></facebook-nickname> <api-key>dbd349b30b6d9fde97b01b827e6be5ed1e4fbe72</api-key> <links> <link> <rel>session</rel> <uri>https://invoicefu-localhost.com/api/session</uri> <methods>GET,POST,DESTROY</methods> </link> <link> <rel>account</rel> <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake</uri> <methods>GET,PUT</methods> </link> <link> <rel>clients</rel> <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/clients</uri> <methods>GET,POST</methods> </link> <link> <rel>new_client</rel> <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/clients/new</uri> <methods>GET</methods> </link> (…) </links> </user>
  • 25. Accept: application/vnd.aspgems.invoicefu.v1.xml THE ACCEPT HEADER HTTP/REST Standard Not everyone Less obvious Unambiguous supports headers Harder to use Resources != or custom types Non standard content- Representations types Version as you need it Skips HTTP server logs
  • 26.
  • 27.
  • 28. templates for new resources > curl "https://invoicefu.com/api/v1/accounts/108-cole-mertz-fake/invoices/new? api_key=ddd349b30b6d9fde97b01b827e6be5ed1e4fbe72&format=json" {"invoice":{"number":"2011/30","issued_on":"2011-12- 12","proforma_id":null,"notes":null,"footer":null,"locale":"en","currency_code":"USD","currency_sym bol":"$","ac_name":"Cole-Mertz#FAKE","ac_company_number_name":"Company number","ac_company_number":"25465828K","ac_tax_number_name":"VAT Number","ac_tax_number":"ES25464828k","ac_address":"234 brecknock road","ac_city":"london","ac_province":null,"ac_postal_code":"n18 5bq","ac_country_name":"United Kingdom","cl_email":null,"cl_name":null,"cl_company_number_name":null,"cl_company_number":null,"cl_ tax_number_name":null,"cl_tax_number":null,"cl_address":null,"cl_city":null,"cl_province":null,"cl_ postal_code":null,"cl_country_name":null,"invoice_lines":[],"discount_percent":null,"tax_lines": [{"name":"TVA","signed_percent":"19.6"}],"paid":"0.0","links": [{"rel":"payments","uri":"https://invoicefu.com/api/accounts/108-cole-mertz- fake/invoices//payments","methods":"POST"}, {"rel":"account","uri":"https://invoicefu.com/api/accounts/108-cole-mertz- fake","methods":"GET,PUT"},{"rel":"client","uri":null,"methods":"GET,PUT,DELETE"}, {"rel":"proforma","uri":null,"methods":"GET,PUT,DELETE"},{"rel":"pdf","uri":null,"methods":"GET"}, {"rel":"invoices","uri":"https://invoicefu.com/api/accounts/108-cole-mertz- fake/invoices","methods":"GET,POST"}]}}j
  • 29. EASy To FIND
  • 30. > curl https://invoicefu.com?format=xml (or curl -H "Accept: application/xml" "https://invoicefu.com") <?xml version="1.0" encoding="UTF-8"?> <invoicefu> <links> <link> <rel>session</rel> <uri>https://invoicefu.com/api/session</uri> <methods>POST.DELETE</methods> </link> <link> <rel>countries</rel> <uri>https://invoicefu.com/api/countries</uri> <methods>GET</methods> </link> <link> <rel>api_v1</rel> <uri>https://invoicefu.com/api/session?api_version=1</uri> <methods>POST.DELETE</methods> </link> <link> <rel>xml_representation</rel> <uri>https://invoicefu.com/api/session?format=xml</uri> <methods>POST.DELETE</methods> </link> <link> <rel>json_representation</rel> <uri>https://invoicefu.com/api/session?format=json</uri> <methods>POST.DELETE</methods> </link> <link> <rel>strict_parameters</rel> <uri>https://invoicefu.com/api/session?strict=true</uri> <methods>POST.DELETE</methods> </link> </links>
  • 31. > curl -d "login=ficticioususer@invoicefu.com&password=yeahyeah" "https://invoicefu.com/api/session?&format=xml <?xml version="1.0" encoding="UTF-8"?> <user> <id>108</id> <name>Nicolas Carroll</name> <email>user000007@invoicefu.com</email> <locale>en</locale> <twitter-nickname nil="true"></twitter-nickname> <facebook-uid nil="true"></facebook-uid> <facebook-nickname nil="true"></facebook-nickname> <api-key>dbd349b30b6d9fde97b01b827e6be5ed1e4fbe72</api-key> <links> <link> <rel>session</rel> <uri>https://invoicefu-localhost.com/api/session</uri> <methods>GET,POST,DESTROY</methods> </link> <link> <rel>account</rel> <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake</uri> <methods>GET,PUT</methods> </link> <link> <rel>clients</rel> <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/clients</uri> <methods>GET,POST</methods> </link> <link> <rel>new_client</rel> <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/clients/new</uri> <methods>GET</methods> </link> <link> <rel>invoices</rel> <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/invoices</uri> <methods>GET,POST</methods> </link> (…) </links> </user>
  • 32. BASIC ACCESS AUTHENTICATION authenticate_or_request_with_http_basic do |login, password| User.find_by_login_and_password login, password end User and password must be passed every time TOKEN Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join ) User.find_by_login_and_api_key( params[:login], params[:api_key] ) Client can send it as a parameter or as a header OAUTH Depends on third party libraries Requires initial registration of client and more integration
  • 35. > curl "https://invoicefu.com/api/accounts/108-cole-mertz-fake/invoices/new? api_key=ddd349b30b6d9fde97b01b827e6be5ed1e4fbe72&format=xml&debug=1" <?xml version="1.0" encoding="UTF-8"?> <errors> <error>extra params found: debug. Allowed params are: account_id,client_id,invoice_id,proforma_id</error> </errors> > curl "https://invoicefu.com/api/accounts/108-cole-mertz-fake/invoices/new? api_key=ddd349b30b6d9fde97b01b827e6be5ed1e4fbe72&format=xml&debug=1&strict=false" <?xml version="1.0" encoding="UTF-8"?> <invoice> <number>2011/30</number> <issued-on>2011-12-11</issued-on> <proforma-id nil="true"></proforma-id> (...) <links> (...) <link> <rel>invoices</rel> <uri>https://invoicefu-localhost.com/api/accounts/108-cole-mertz-fake/invoices</uri> <methods>GET,POST</methods> </link> </links> </invoice>
  • 36.
  • 37. helping your users WADL json schema
  • 38. { <?xml version="1.0"?> "name":"Product", <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" "properties":{ xsi:schemaLocation="http://wadl.dev.java.net/2009/02 wadl.xsd" "id":{ xmlns:tns="urn:yahoo:yn" "type":"number", xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:yn="urn:yahoo:yn" "description":"Product identifier", xmlns:ya="urn:yahoo:api" "required":true xmlns="http://wadl.dev.java.net/2009/02"> }, <grammars> "name":{ <include "description":"Name of the href="NewsSearchResponse.xsd"/> product", <include "type":"string", href="Error.xsd"/> "required":true </grammars> }, "price":{ <resources base="http://api.search.yahoo.com/NewsSearchService/V1/"> <resource path="newsSearch"> "required":true, <method name="GET" id="search"> "type": "number", <request> "minimum":0, <param name="appid" type="xsd:string" "required":true style="query" required="true"/> 22 }, <param name="type" style="query" default="all"> "tags":{ <option value="all"/> "type":"array", <option value="any"/> "items":{ <option value="phrase"/> "type":"string" </param> } <param name="start" style="query" type="xsd:int" default="1"/> <param name="language" style="query" type="xsd:string"/> } </request> }, <response status="200"> "links":[ <representation mediaType="application/xml" { element="yn:ResultSet"/> "rel":"full", </response> "href":"{id}" <response status="400"> }, <representation mediaType="application/xml" { element="ya:Error"/> "rel":"comments", </response> "href":"comments/?id={id}" </method> </resource> } </resources> ] } </application>