Upload
sacheen-dhanjie
View
138
Download
5
Embed Size (px)
Citation preview
Intro to the WWWSACHEEN DHANJIE
Sacheen DhanjieSenior Developer @ Afrihost.com
So you want to learn how to code?•Coding takes time, practice and patience.
•Don’t give up, there’s always a solution.
•Think logically.
Hyper Text Transfer Protocol• <protocol>://<subdomain><server><port:80><path>
• sacheen.plex.com:32400/web/index.html• Request / Response
• Client initiate’s a request • Server generates a response
• HTTP is stateless • Server /Client does not keep record of the connection
Request / Response
Request/Response• Each Request contains information:
• The HOST: www.google.com• The COOKIES: This may contain a session that the server can use to identify you - because http is stateless
• The CONTENT: what kind information you sending the server• The METHOD that the server needs to perform, GET,PUT,POST,DELETE
• There are other parameters sent to the server, but the above covers the basics
Request/Response
Request/Response• Each Response contains information:• The STATUS: the code that determines the success or failure of a request,• 200, 500, 404, 503, 301, 302…etc
• The CONTENT: The data sent back by the server• There is more information sent back, but the above is the the most important
GET• Get data from the server
POST• Update/Create data on the server, most developers use POST as creation
as wellPUT• Create/Update data on the server
DELETE• DELETE’s data from the server
HEAD• Identical to GET except that the server MUST NOT return a message-
body in the response.OPTIONS• Represents a request for information about the communication options
available on the request/response chain identified
GET• Request
• URL: https://www.afrihost.com/• Content: none
• Response:
• CONTENT: the page you requested• STATUS: 200
POST• Request
• URL: https://www.afrihost.com/testimonial• Content: name=bob&age=5&message=amazing site
• Response:
• CONTENT: some success page• STATUS: 200
PUT• Request
• URL: https://www.afrihost.com/testimonial• Content: name=bob&age=5&message=amazing site
• Response:
• CONTENT: some success page• STATUS: 200
DELETE• Request
• URL: https://www.afrihost.com/testimonial/100• Content: id=100 [the spec does not forbid or discourage it]
• Response:
• CONTENT: some delete success page• STATUS: 200
ExamplesPOST /en/api/of/telkom-lines-speed HTTP/1.1Host: clientzone.trunkCache-Control: no-cachePostman-Token: 4977bd45-aea9-c84b-4b15-94e909fd7e76Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW----WebKitFormBoundary7MA4YWxkTrZu0gWContent-Disposition: form-data; name="number"0119185642----WebKitFormBoundary7MA4YWxkTrZu0gW
ExamplesPUT /en/api/of/telkom-lines-speed HTTP/1.1Host: clientzone.trunkCache-Control: no-cachePostman-Token: 2719f53b-8f52-3318-f154-ccf9adc224f2Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW----WebKitFormBoundary7MA4YWxkTrZu0gWContent-Disposition: form-data; name="number"0119185642----WebKitFormBoundary7MA4YWxkTrZu0gW
Examples
GET /en/api/of/dsl-lines-products HTTP/1.1Host: clientzone.trunkCache-Control: no-cachePostman-Token: 28c6208a-25ba-8fb2-8678-d0b4871fc2bc
Accessing data in PHP• $_GET[“data”]; //somepage.com/?data=steve• $_POST[“data”] somepage.com/some-path Content:
data=steve• parse_str(file_get_contents('php://input'), $put) put
data is sent via stdin $put[“data”]
ExamplesAfrihost Usage Example:• https://clientzone.afrihost.com/order/#/• Afrihost Mobile App
Closing• The request-response conversation is the fundamental
process that drives all communication on the web.
• Regardless of the language you use, the type of application you build (web, mobile, JSON API) or the development philosophy you follow, the end goal of an application is always to understand each request and create and return the appropriate response
• KISS – KEEP IT SIMPLE STUPID – don’t over complicate things
• Do one thing and do it well
Links• https://en.wikipedia.org/wiki/List_of_HTTP_status_codes• http://
symfony.com/doc/current/book/http_fundamentals.html• http://
stackoverflow.com/questions/671118/what-exactly-is-restful-programming
• https://packagist.org/packages/sacheen/rest-hook-bundle• http://
php.net/manual/en/features.file-upload.put-method.php