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

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

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