SlideShare a Scribd company logo
1 of 31
Download to read offline
Your REST API
using Laravel
@sulaeman2014 by Sulaeman
di kelon dulu
https://github.com/feelinc/Your-Laravel-Api
@sulaeman2014 by Sulaeman
Postman - REST Client
http://bit.ly/1kuDLtc
@sulaeman2014 by Sulaeman
Metode HTTP
OPTIONS Untuk mengetahui persyaratan dan atau kemampuan server dalam menerima request maupun
memberikan response
HEAD Untuk mengetahui header yang tersedia dari HTTP server
GET Hanya digunakan untuk mengambil data
POST Hanya digunakan untuk membuat data baru
PATCH Hanya digunakan untuk memperbaharui sebagian data
PUT Hanya digunakan untuk memperbaharui data secara lengkap
DELETE Hanya untuk menghapus data
@sulaeman2014 by Sulaeman
Default Response Header
Header Value
Access-Control-Allow-Credentials true
Access-Control-Allow-Origin *
Access-Control-Allow-Methods OPTIONS, HEAD, GET, POST, PUT, PATCH, DELETE
Access-Control-Allow-Headers Origin, Accept, Content-Type, Content-MD5, Content-Range,
Content-Disposition, Authorization
@sulaeman2014 by Sulaeman
HTTP Status
● 200 OK - Respon sukses untuk metode GET, PUT, PATCH or DELETE. Bisa juga digunakan untuk metode POST yang
tidak berhasil membuat data baru.
● 201 Created - Respon sukses untuk metode POST
● 204 No Content - Respon sukses untuk metode DELETE
● 304 Not Modified - Digunakan berhubungan dengan metode caching via HTTP header
● 400 Bad Request - Request data tidak valid
● 401 Unauthorized - Jika client request tidak ter-otentikasi
● 403 Forbidden - Jika akses terhadap endpoint tidak diperbolehkan
● 404 Not Found - You Now What
● 405 Method Not Allowed - Jika request terhadap endpoint tidak diperbolehkan berdasarkan user yang ter-otentikasi
● 410 Gone - Jika endpoint sudah tidak tersedia
● 415 Unsupported Media Type - Jika format konten request tidak valid
● 422 Unprocessable Entity - Bisa digunakan untuk validasi form
● 429 Too Many Requests - Jika request ditolak berhubungan dengan limitasi request per periode
@sulaeman2014 by Sulaeman
HTTP Caching
ETag & If-None-Match
ETag hash atau checksum dari konten response
If-None-Match hash atau checksum ketika melakukan request. API memberikan response 304 -
Not Modified jika ETag dari konten response cocok dengan If-None-Match
@sulaeman2014 by Sulaeman
Request Limiter
Periode dapat ditentukan bedasarkan per-jam atau per-hari.
Respon HTTP header untuk setiap request
Header Keterangan
X-Rate-Limit-Limit Total request yang diperbolehkan dalam periode sekarang
X-Rate-Limit-Remaining Total sisa request yang diperbolehkan dalam periode sekarang
X-Rate-Limit-Reset Sisa waktu periode sekarang, dalam detik
@sulaeman2014 by Sulaeman
Versioning
api.domain.com/v1/
api.domain.com/v2/
@sulaeman2014 by Sulaeman
Pagination
Link: <https://api.domain.com/v1/data?offset=3&limit=100>; rel="next", <https:
//api.domain.com/v1/data?offset=50&limit=100>; rel="last"
Available “rel” : next, last, first, prev
@sulaeman2014 by Sulaeman
Otentikasi
biasa nya sih nyebut “Authentication”
@sulaeman2014 by Sulaeman
Otentikasi
Aplikasi = OAuth 2
User = Basic Auth + OAuth 2 Access Token
@sulaeman2014 by Sulaeman
Otentikasi Aplikasi
Scope
read write
@sulaeman2014 by Sulaeman
Otentikasi User
Group
Administrators Users
@sulaeman2014 by Sulaeman
Otentikasi User
Permissions
user.create user.update user.viewuser.delete
@sulaeman2014 by Sulaeman
POST /authorization
REQUEST
Header Content-Type: application/json
Content-MD5: md5($stringRequestBody.$clientSecret)
Body (raw) {"grant_type":"client_credentials","client_id":"
JXSb6nEzpQ0e3WAWjsSsZurCaLy0knDjzkwxRlJs","client_secret":"
C4vpZLRI2kncfXJQZ9l0hdnaTCTupyqF1deCVEPf","scope":"read,write"}
RESPONSE
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body {
access_token: "jU5vKEBSPSVqRwEXwjIM0N1YefCG0hwqTK5i0UC3"
token_type: "bearer"
expires: 1399017374
expires_in: 3600
}
Otorisasi Aplikasi / Client
@sulaeman2014 by Sulaeman
POST /api/v1/authenticate
REQUEST
Header Authorization: Basic bWVAc3VsYWVtYW4uY29tOndoYXQ=
Content-MD5: md5($stringRequestBody.$clientSecret)
Body(form-data) access_token=NMy2Q0zKwoW406DN2xEpDYUpjGX7rDAabXbadQNA
RESPONSE
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body {
access_token: "qJAq492q8x2H2uZUmUN5pQPS8fOLjinDbbMCZ4DF"
token_type: "bearer"
expires: 1399027251
expires_in: 3600
refresh_token: "81pG21LwQVZVN1fcWWCzqLhGkNtcmxEcdXMoyeO9"
user: {
id: 1,
email: "me@sulaeman.com"
display_name: "Sulaeman Tea"
last_login: "2014-05-02T16:40:51+07:00"
is_activated: true
registered_at: "-001-11-30T00:00:00+07:07"
updated_at: "2014-05-02T16:40:51+07:00"
groups: ["Administrators"]
}
Otentikasi User
POST /authorization
REQUEST
Header Content-Type: application/json
Content-MD5: md5($stringRequestBody.$clientSecret)
Body (raw) {"grant_type":"refresh_token","refresh_token":"
81pG21LwQVZVN1fcWWCzqLhGkNtcmxEcdXMoyeO9","client_id":"
JXSb6nEzpQ0e3WAWjsSsZurCaLy0knDjzkwxRlJs","client_secret":"
C4vpZLRI2kncfXJQZ9l0hdnaTCTupyqF1deCVEPf","state":3438732984782937489}
RESPONSE
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body {
access_token: "H6MUOmYSAUG2nmOrvPXQvFWMJFXOELwP34kjPsza"
token_type: "bearer"
expires: 1399027533
expires_in: 3600
}
Refresh Token Aplikasi / Client
@sulaeman2014 by Sulaeman
POST /api/v1/authenticate
REQUEST
Header Authorization: Basic d3JvbmdAdXNlci5jb206d2hhdA==
Content-MD5: md5($stringRequestBody.$clientSecret)
Body(form-data) access_token=H6MUOmYSAUG2nmOrvPXQvFWMJFXOELwP34kjPsza
RESPONSE
Status 401 Unauthorized
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body {"message":"User was not found."}
Otentikasi User
Gunakan user credential yang salah
@sulaeman2014 by Sulaeman
Resources
agak enak baca nya? ato malah buka google translate?
@sulaeman2014 by Sulaeman
POST /api/v1/users Membuat / Mendaftarkan User
REQUEST
Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM
Content-Type: application/json
Content-MD5: md5($stringRequestBody.$clientSecret)
Body (raw) {"email":"neneng.caur@domain.com","password":"abcabc","group":"Users","activated":
true,"first_name":"Neneng","last_name":""}
RESPONSE
Status 201 Created
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body {
id: 2,
email: "neneng.caur@domain.com"
first_name: "Neneng"
last_name: ""
display_name: "Neneng"
last_login: null
is_activated: true
registered_at: "2014-05-03T04:29:34+07:00"
updated_at: "2014-05-03T04:29:34+07:00"
groups: ["Users"]
GET /api/v1/users/:id Mengambil User
REQUEST Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM
RESPONSE
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body {
id: 2,
email: "neneng.caur@domain.com"
first_name: "Neneng"
last_name: ""
display_name: "Neneng"
last_login: null
is_activated: true
registered_at: "2014-05-03T04:29:34+07:00"
updated_at: "2014-05-03T04:29:34+07:00"
groups: ["Users"]
}
@sulaeman2014 by Sulaeman
PATCH /api/v1/users/:id Memperbaharui Data User (sebagian)
REQUEST
Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM
Content-Type: application/json
Content-MD5: md5($stringRequestBody.$clientSecret)
Body (raw) {"first_name":"Neneng","last_name":"Caur"}
RESPONSE
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body {
id: 2,
email: "neneng.caur@domain.com"
first_name: "Neneng"
last_name: "Caur"
display_name: "Neneng Caur"
last_login: null
is_activated: true
registered_at: "2014-05-03T04:29:34+07:00"
updated_at: "2014-05-03T04:29:34+07:00"
groups: ["Users"]
}
PUT /api/v1/users/:id Memperbaharui Data User
REQUEST
Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM
Content-Type: application/json
Content-MD5: md5($stringRequestBody.$clientSecret)
Body (raw) {"email":"neneng.caur@domain.com","password":"abcabc","group":"Users","activated":
false,"first_name":"Neneng","last_name":"Caur"}
RESPONSE
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body {
id: 2,
email: "neneng.caur@domain.com"
first_name: "Neneng"
last_name: "Caur"
display_name: "Neneng Caur"
last_login: null
is_activated: false
registered_at: "2014-05-03T04:29:34+07:00"
updated_at: "2014-05-03T04:29:34+07:00"
groups: ["Users"]
}
DELETE /api/v1/users/:id Menghapus Data User
REQUEST Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM
RESPONSE
Status 204 No Content
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body
@sulaeman2014 by Sulaeman
GET /api/v1/users Mengambil Daftar User
REQUEST
Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM
Param offset=1&limit=1
RESPONSE
Header X-Rate-Limit-Limit: 5000
X-Rate-Limit-Remaining: 4999
X-Rate-Limit-Reset: 3600
Body [
{
id: 1
email: "neneng.caur@domain.com"
first_name: "Neneng"
last_name: ""
display_name: "Neneng"
last_login: null
is_activated: true
registered_at: "2014-05-03T12:07:50+07:00"
updated_at: "2014-05-03T12:07:50+07:00"
}
]
@sulaeman2014 by Sulaeman
PROBLEM
ASEM!
@sulaeman2014 by Sulaeman
Apache Web Server
CGI/Fast CGI
HTTP Basic Auth
Server variable PHP_AUTH_USER dan PHP_AUTH_PW nyasar entah kemana :P
SOLUSI
.htaccess
# Fix the HTTP basic auth
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
@sulaeman2014 by Sulaeman
Nginx Web Server
HTTP “Authorization” header
Server variable HTTP_AUTHORIZATION nyasar entah kemana :P
SOLUSI
Konfigurasi Nginx server
ignore_invalid_headers off;
@sulaeman2014 by Sulaeman
Terima Kasih
Sulaeman
@sulaeman
http://id.linkedin.com/in/sulaeman

More Related Content

What's hot

Introduction to RESTful Web Services
Introduction to RESTful Web ServicesIntroduction to RESTful Web Services
Introduction to RESTful Web ServicesFelipe Dornelas
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座Li Yi
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsStormpath
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSKatrien Verbert
 
Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web servicesmwinteringham
 
When RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPWhen RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPMatthew Turland
 
Cross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORSCross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORSMichael Neale
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8Andrei Jechiu
 
RESTful Web Services in Drupal7
RESTful Web Services in Drupal7RESTful Web Services in Drupal7
RESTful Web Services in Drupal7bmeme
 
Secure RESTful API Automation With JavaScript
Secure RESTful API Automation With JavaScriptSecure RESTful API Automation With JavaScript
Secure RESTful API Automation With JavaScriptJonathan LeBlanc
 

What's hot (20)

httpie
httpiehttpie
httpie
 
Introduction to RESTful Web Services
Introduction to RESTful Web ServicesIntroduction to RESTful Web Services
Introduction to RESTful Web Services
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RS
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web services
 
When RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPWhen RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTP
 
Cross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORSCross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORS
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
L18 REST API Design
L18 REST API DesignL18 REST API Design
L18 REST API Design
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
RESTful Web Services in Drupal7
RESTful Web Services in Drupal7RESTful Web Services in Drupal7
RESTful Web Services in Drupal7
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Secure RESTful API Automation With JavaScript
Secure RESTful API Automation With JavaScriptSecure RESTful API Automation With JavaScript
Secure RESTful API Automation With JavaScript
 

Similar to Your rest api using laravel

Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restfulknight1128
 
SCWCD 2. servlet req - resp (cap3 - cap4)
SCWCD 2. servlet   req - resp (cap3 - cap4)SCWCD 2. servlet   req - resp (cap3 - cap4)
SCWCD 2. servlet req - resp (cap3 - cap4)Francesco Ierna
 
Varnish Cache and Django (Falcon, Flask etc)
Varnish Cache and Django (Falcon, Flask etc)Varnish Cache and Django (Falcon, Flask etc)
Varnish Cache and Django (Falcon, Flask etc)Данил Иванов
 
"Best Practices for Designing a Pragmatic RESTful API
 "Best Practices for Designing a Pragmatic RESTful API "Best Practices for Designing a Pragmatic RESTful API
"Best Practices for Designing a Pragmatic RESTful APIITCP Community
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAnuchit Chalothorn
 
Indic threads delhi13-rest-anirudh
Indic threads delhi13-rest-anirudhIndic threads delhi13-rest-anirudh
Indic threads delhi13-rest-anirudhAnirudh Bhatnagar
 
Api design and development
Api design and developmentApi design and development
Api design and developmentoquidave
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증박 민규
 
Test in Rest. API testing with the help of Rest Assured.
Test in Rest. API testing with the help of  Rest Assured.Test in Rest. API testing with the help of  Rest Assured.
Test in Rest. API testing with the help of Rest Assured.Artem Korchevyi
 
API testing with the help of Rest Assured
API testing with the help of  Rest Assured API testing with the help of  Rest Assured
API testing with the help of Rest Assured Artem Korchevyi
 
Webservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTWebservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTPradeep Kumar
 

Similar to Your rest api using laravel (20)

Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restful
 
HTTP Basics Demo
HTTP Basics DemoHTTP Basics Demo
HTTP Basics Demo
 
SCWCD 2. servlet req - resp (cap3 - cap4)
SCWCD 2. servlet   req - resp (cap3 - cap4)SCWCD 2. servlet   req - resp (cap3 - cap4)
SCWCD 2. servlet req - resp (cap3 - cap4)
 
Apex REST
Apex RESTApex REST
Apex REST
 
Php workshop L03 superglobals
Php workshop L03 superglobalsPhp workshop L03 superglobals
Php workshop L03 superglobals
 
Varnish Cache and Django (Falcon, Flask etc)
Varnish Cache and Django (Falcon, Flask etc)Varnish Cache and Django (Falcon, Flask etc)
Varnish Cache and Django (Falcon, Flask etc)
 
Rest API
Rest APIRest API
Rest API
 
REST API V2
REST API V2REST API V2
REST API V2
 
"Best Practices for Designing a Pragmatic RESTful API
 "Best Practices for Designing a Pragmatic RESTful API "Best Practices for Designing a Pragmatic RESTful API
"Best Practices for Designing a Pragmatic RESTful API
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web Services
 
Troubleshooting.pptx
Troubleshooting.pptxTroubleshooting.pptx
Troubleshooting.pptx
 
Ajax basics
Ajax basicsAjax basics
Ajax basics
 
Indic threads delhi13-rest-anirudh
Indic threads delhi13-rest-anirudhIndic threads delhi13-rest-anirudh
Indic threads delhi13-rest-anirudh
 
Api design and development
Api design and developmentApi design and development
Api design and development
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증
 
Basics Of Servlet
Basics Of ServletBasics Of Servlet
Basics Of Servlet
 
Test in Rest. API testing with the help of Rest Assured.
Test in Rest. API testing with the help of  Rest Assured.Test in Rest. API testing with the help of  Rest Assured.
Test in Rest. API testing with the help of Rest Assured.
 
API testing with the help of Rest Assured
API testing with the help of  Rest Assured API testing with the help of  Rest Assured
API testing with the help of Rest Assured
 
Webservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTWebservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and REST
 

Recently uploaded

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
"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
 
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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
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
 
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
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Recently uploaded (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
"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
 
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!
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
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
 
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
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

Your rest api using laravel

  • 1. Your REST API using Laravel @sulaeman2014 by Sulaeman
  • 2.
  • 4. Postman - REST Client http://bit.ly/1kuDLtc @sulaeman2014 by Sulaeman
  • 5. Metode HTTP OPTIONS Untuk mengetahui persyaratan dan atau kemampuan server dalam menerima request maupun memberikan response HEAD Untuk mengetahui header yang tersedia dari HTTP server GET Hanya digunakan untuk mengambil data POST Hanya digunakan untuk membuat data baru PATCH Hanya digunakan untuk memperbaharui sebagian data PUT Hanya digunakan untuk memperbaharui data secara lengkap DELETE Hanya untuk menghapus data @sulaeman2014 by Sulaeman
  • 6. Default Response Header Header Value Access-Control-Allow-Credentials true Access-Control-Allow-Origin * Access-Control-Allow-Methods OPTIONS, HEAD, GET, POST, PUT, PATCH, DELETE Access-Control-Allow-Headers Origin, Accept, Content-Type, Content-MD5, Content-Range, Content-Disposition, Authorization @sulaeman2014 by Sulaeman
  • 7. HTTP Status ● 200 OK - Respon sukses untuk metode GET, PUT, PATCH or DELETE. Bisa juga digunakan untuk metode POST yang tidak berhasil membuat data baru. ● 201 Created - Respon sukses untuk metode POST ● 204 No Content - Respon sukses untuk metode DELETE ● 304 Not Modified - Digunakan berhubungan dengan metode caching via HTTP header ● 400 Bad Request - Request data tidak valid ● 401 Unauthorized - Jika client request tidak ter-otentikasi ● 403 Forbidden - Jika akses terhadap endpoint tidak diperbolehkan ● 404 Not Found - You Now What ● 405 Method Not Allowed - Jika request terhadap endpoint tidak diperbolehkan berdasarkan user yang ter-otentikasi ● 410 Gone - Jika endpoint sudah tidak tersedia ● 415 Unsupported Media Type - Jika format konten request tidak valid ● 422 Unprocessable Entity - Bisa digunakan untuk validasi form ● 429 Too Many Requests - Jika request ditolak berhubungan dengan limitasi request per periode @sulaeman2014 by Sulaeman
  • 8. HTTP Caching ETag & If-None-Match ETag hash atau checksum dari konten response If-None-Match hash atau checksum ketika melakukan request. API memberikan response 304 - Not Modified jika ETag dari konten response cocok dengan If-None-Match @sulaeman2014 by Sulaeman
  • 9. Request Limiter Periode dapat ditentukan bedasarkan per-jam atau per-hari. Respon HTTP header untuk setiap request Header Keterangan X-Rate-Limit-Limit Total request yang diperbolehkan dalam periode sekarang X-Rate-Limit-Remaining Total sisa request yang diperbolehkan dalam periode sekarang X-Rate-Limit-Reset Sisa waktu periode sekarang, dalam detik @sulaeman2014 by Sulaeman
  • 11. Pagination Link: <https://api.domain.com/v1/data?offset=3&limit=100>; rel="next", <https: //api.domain.com/v1/data?offset=50&limit=100>; rel="last" Available “rel” : next, last, first, prev @sulaeman2014 by Sulaeman
  • 12. Otentikasi biasa nya sih nyebut “Authentication” @sulaeman2014 by Sulaeman
  • 13. Otentikasi Aplikasi = OAuth 2 User = Basic Auth + OAuth 2 Access Token @sulaeman2014 by Sulaeman
  • 16. Otentikasi User Permissions user.create user.update user.viewuser.delete @sulaeman2014 by Sulaeman
  • 17. POST /authorization REQUEST Header Content-Type: application/json Content-MD5: md5($stringRequestBody.$clientSecret) Body (raw) {"grant_type":"client_credentials","client_id":" JXSb6nEzpQ0e3WAWjsSsZurCaLy0knDjzkwxRlJs","client_secret":" C4vpZLRI2kncfXJQZ9l0hdnaTCTupyqF1deCVEPf","scope":"read,write"} RESPONSE Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body { access_token: "jU5vKEBSPSVqRwEXwjIM0N1YefCG0hwqTK5i0UC3" token_type: "bearer" expires: 1399017374 expires_in: 3600 } Otorisasi Aplikasi / Client @sulaeman2014 by Sulaeman
  • 18. POST /api/v1/authenticate REQUEST Header Authorization: Basic bWVAc3VsYWVtYW4uY29tOndoYXQ= Content-MD5: md5($stringRequestBody.$clientSecret) Body(form-data) access_token=NMy2Q0zKwoW406DN2xEpDYUpjGX7rDAabXbadQNA RESPONSE Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body { access_token: "qJAq492q8x2H2uZUmUN5pQPS8fOLjinDbbMCZ4DF" token_type: "bearer" expires: 1399027251 expires_in: 3600 refresh_token: "81pG21LwQVZVN1fcWWCzqLhGkNtcmxEcdXMoyeO9" user: { id: 1, email: "me@sulaeman.com" display_name: "Sulaeman Tea" last_login: "2014-05-02T16:40:51+07:00" is_activated: true registered_at: "-001-11-30T00:00:00+07:07" updated_at: "2014-05-02T16:40:51+07:00" groups: ["Administrators"] } Otentikasi User
  • 19. POST /authorization REQUEST Header Content-Type: application/json Content-MD5: md5($stringRequestBody.$clientSecret) Body (raw) {"grant_type":"refresh_token","refresh_token":" 81pG21LwQVZVN1fcWWCzqLhGkNtcmxEcdXMoyeO9","client_id":" JXSb6nEzpQ0e3WAWjsSsZurCaLy0knDjzkwxRlJs","client_secret":" C4vpZLRI2kncfXJQZ9l0hdnaTCTupyqF1deCVEPf","state":3438732984782937489} RESPONSE Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body { access_token: "H6MUOmYSAUG2nmOrvPXQvFWMJFXOELwP34kjPsza" token_type: "bearer" expires: 1399027533 expires_in: 3600 } Refresh Token Aplikasi / Client @sulaeman2014 by Sulaeman
  • 20. POST /api/v1/authenticate REQUEST Header Authorization: Basic d3JvbmdAdXNlci5jb206d2hhdA== Content-MD5: md5($stringRequestBody.$clientSecret) Body(form-data) access_token=H6MUOmYSAUG2nmOrvPXQvFWMJFXOELwP34kjPsza RESPONSE Status 401 Unauthorized Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body {"message":"User was not found."} Otentikasi User Gunakan user credential yang salah @sulaeman2014 by Sulaeman
  • 21. Resources agak enak baca nya? ato malah buka google translate? @sulaeman2014 by Sulaeman
  • 22. POST /api/v1/users Membuat / Mendaftarkan User REQUEST Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM Content-Type: application/json Content-MD5: md5($stringRequestBody.$clientSecret) Body (raw) {"email":"neneng.caur@domain.com","password":"abcabc","group":"Users","activated": true,"first_name":"Neneng","last_name":""} RESPONSE Status 201 Created Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body { id: 2, email: "neneng.caur@domain.com" first_name: "Neneng" last_name: "" display_name: "Neneng" last_login: null is_activated: true registered_at: "2014-05-03T04:29:34+07:00" updated_at: "2014-05-03T04:29:34+07:00" groups: ["Users"]
  • 23. GET /api/v1/users/:id Mengambil User REQUEST Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM RESPONSE Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body { id: 2, email: "neneng.caur@domain.com" first_name: "Neneng" last_name: "" display_name: "Neneng" last_login: null is_activated: true registered_at: "2014-05-03T04:29:34+07:00" updated_at: "2014-05-03T04:29:34+07:00" groups: ["Users"] } @sulaeman2014 by Sulaeman
  • 24. PATCH /api/v1/users/:id Memperbaharui Data User (sebagian) REQUEST Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM Content-Type: application/json Content-MD5: md5($stringRequestBody.$clientSecret) Body (raw) {"first_name":"Neneng","last_name":"Caur"} RESPONSE Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body { id: 2, email: "neneng.caur@domain.com" first_name: "Neneng" last_name: "Caur" display_name: "Neneng Caur" last_login: null is_activated: true registered_at: "2014-05-03T04:29:34+07:00" updated_at: "2014-05-03T04:29:34+07:00" groups: ["Users"] }
  • 25. PUT /api/v1/users/:id Memperbaharui Data User REQUEST Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM Content-Type: application/json Content-MD5: md5($stringRequestBody.$clientSecret) Body (raw) {"email":"neneng.caur@domain.com","password":"abcabc","group":"Users","activated": false,"first_name":"Neneng","last_name":"Caur"} RESPONSE Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body { id: 2, email: "neneng.caur@domain.com" first_name: "Neneng" last_name: "Caur" display_name: "Neneng Caur" last_login: null is_activated: false registered_at: "2014-05-03T04:29:34+07:00" updated_at: "2014-05-03T04:29:34+07:00" groups: ["Users"] }
  • 26. DELETE /api/v1/users/:id Menghapus Data User REQUEST Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM RESPONSE Status 204 No Content Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body @sulaeman2014 by Sulaeman
  • 27. GET /api/v1/users Mengambil Daftar User REQUEST Header Authorization: Bearer 7E81Ojh0pSLgqtbHAHfYRrcfJ2HWNNYrNL4CqjEM Param offset=1&limit=1 RESPONSE Header X-Rate-Limit-Limit: 5000 X-Rate-Limit-Remaining: 4999 X-Rate-Limit-Reset: 3600 Body [ { id: 1 email: "neneng.caur@domain.com" first_name: "Neneng" last_name: "" display_name: "Neneng" last_login: null is_activated: true registered_at: "2014-05-03T12:07:50+07:00" updated_at: "2014-05-03T12:07:50+07:00" } ] @sulaeman2014 by Sulaeman
  • 29. Apache Web Server CGI/Fast CGI HTTP Basic Auth Server variable PHP_AUTH_USER dan PHP_AUTH_PW nyasar entah kemana :P SOLUSI .htaccess # Fix the HTTP basic auth RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] @sulaeman2014 by Sulaeman
  • 30. Nginx Web Server HTTP “Authorization” header Server variable HTTP_AUTHORIZATION nyasar entah kemana :P SOLUSI Konfigurasi Nginx server ignore_invalid_headers off; @sulaeman2014 by Sulaeman