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

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Recently uploaded (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

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