Dev traning 2016 intro to the web
-
Upload
sacheen-dhanjie -
Category
Software
-
view
141 -
download
5
Transcript of Dev traning 2016 intro to the web
![Page 1: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/1.jpg)
Intro to the WWWSACHEEN DHANJIE
![Page 2: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/2.jpg)
Sacheen DhanjieSenior Developer @ Afrihost.com
![Page 3: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/3.jpg)
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.
![Page 4: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/4.jpg)
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
![Page 5: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/5.jpg)
Request / Response
![Page 6: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/6.jpg)
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
![Page 7: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/7.jpg)
Request/Response
![Page 8: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/8.jpg)
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
![Page 9: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/9.jpg)
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
![Page 10: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/10.jpg)
GET• Request
• URL: https://www.afrihost.com/• Content: none
• Response:
• CONTENT: the page you requested• STATUS: 200
![Page 11: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/11.jpg)
POST• Request
• URL: https://www.afrihost.com/testimonial• Content: name=bob&age=5&message=amazing site
• Response:
• CONTENT: some success page• STATUS: 200
![Page 12: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/12.jpg)
PUT• Request
• URL: https://www.afrihost.com/testimonial• Content: name=bob&age=5&message=amazing site
• Response:
• CONTENT: some success page• STATUS: 200
![Page 13: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/13.jpg)
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
![Page 14: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/14.jpg)
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
![Page 15: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/15.jpg)
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
![Page 16: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/16.jpg)
Examples
GET /en/api/of/dsl-lines-products HTTP/1.1Host: clientzone.trunkCache-Control: no-cachePostman-Token: 28c6208a-25ba-8fb2-8678-d0b4871fc2bc
![Page 17: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/17.jpg)
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”]
![Page 18: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/18.jpg)
ExamplesAfrihost Usage Example:• https://clientzone.afrihost.com/order/#/• Afrihost Mobile App
![Page 19: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/19.jpg)
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
![Page 20: Dev traning 2016 intro to the web](https://reader036.fdocuments.net/reader036/viewer/2022062821/58acc7b01a28abd3048b6231/html5/thumbnails/20.jpg)
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