Upload
yogiindragiri
View
218
Download
0
Embed Size (px)
Citation preview
8/10/2019 Http and Json
1/33
HTTP and JSON
Todi Adiyatmo, ST., M.I.T.
8/10/2019 Http and Json
2/33
Examining HTTP Request Under the hood
Curl The popular command line tool to create web
request
JSON
File Example available on ~layanan_web/code/curl
Topic Outline
8/10/2019 Http and Json
3/33
Before we learn about web service, its betterfor us to learn how HTTP request really work The protocol
The Header The Respond
The method involved
HTTP Request
8/10/2019 Http and Json
4/33
HTTP Request
8/10/2019 Http and Json
5/33
Chrome is a mandatory browser in this class
Chrome developer tools (f12) Analyze behind the hood
Request response CSS Editing
Javascript debugger
Etc
Chrome Developer Tools
8/10/2019 Http and Json
6/33
The request and response is done in HTTP
Web Server acting as Server and client
8/10/2019 Http and Json
7/33
Command line tool providing library for datatransfer across various protocol
Available in linux and PHP PECL module
Curl is going to be one of your primary toolwhen calling and Web Service API
Using HTTP Protocol to read data fromvarious language / System ! (Cross Platform)
Curl
8/10/2019 Http and Json
8/33
Curl in action (HTML Data)
8/10/2019 Http and Json
9/33
Curl in action (JSON Data)
8/10/2019 Http and Json
10/33
Network Stack
8/10/2019 Http and Json
11/33
Cross Platform API Service
8/10/2019 Http and Json
12/33
We can write http request with differentProgramming Language Easyly JAVA
PHP Ruby
ASP
Every Programming Language have build a
http library
HTTP Programming Library
8/10/2019 Http and Json
13/33
Load your PHP Curl extension first
8/10/2019 Http and Json
14/33
Curl in PHP
8/10/2019 Http and Json
15/33
Result :
8/10/2019 Http and Json
16/33
Examine the Request and Response
8/10/2019 Http and Json
17/33
Data.php (JSON Server)
JSON_Client.php (Client)
Simple Server - Client
8/10/2019 Http and Json
18/33
Data.php
8/10/2019 Http and Json
19/33
JSON_Client.php
8/10/2019 Http and Json
20/33
Javascript Object Notation
Kalkulator Atribut : merk, pemilik
JSON
8/10/2019 Http and Json
21/33
JSON (2)
8/10/2019 Http and Json
22/33
Other more complex example
8/10/2019 Http and Json
23/33
Simple Structure
Can be eval() at javascript side, easier codeexecution
Easy to read (when properly formatted)
Why JSON
8/10/2019 Http and Json
24/33
Network Request
8/10/2019 Http and Json
25/33
And response..
8/10/2019 Http and Json
26/33
Common HTTP Status
8/10/2019 Http and Json
27/33
2xx Success
3xx Redirect
4xx Client Error
5xx Server Error
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Common HTTP Status (2)
http://en.wikipedia.org/wiki/List_of_HTTP_status_codeshttp://en.wikipedia.org/wiki/List_of_HTTP_status_codeshttp://en.wikipedia.org/wiki/List_of_HTTP_status_codeshttp://en.wikipedia.org/wiki/List_of_HTTP_status_codes8/10/2019 Http and Json
28/33
200 Ok Should be in most response
201 Created
After creating RESTfull instance 202 Accepted
Upload file
204 No Content
Remember this code for later use
2xx Code - Success
8/10/2019 Http and Json
29/33
301 Move Permanently Access google.com -> google.co.id
304 Not Modified
Cache mechanism
3xx Code - Redirect
8/10/2019 Http and Json
30/33
400 Bad request ( broken request header bad network)
401
Unathorized 403
Forbidden ( access to restricted area)
404 Page not found
4xx Code Client Error
8/10/2019 Http and Json
31/33
500 Server Error (When your server is broken)
501
Not implemented (API) 502
Bad gateway
508 Loop Permanent loop (bad code)
5xx Server Error
8/10/2019 Http and Json
32/33
The response code is important for the RESTweb service were going to build
Remember the important code
200 301
403
404
501
Important Notes
8/10/2019 Http and Json
33/33
http://secretgeek.net/json_3mins.asp
More at :
http://secretgeek.net/json_3mins.asphttp://secretgeek.net/json_3mins.asp