20
Intro to the WWW SACHEEN DHANJIE

Dev traning 2016 intro to the web

Embed Size (px)

Citation preview

Page 1: Dev traning 2016   intro to the web

Intro to the WWWSACHEEN DHANJIE

Page 2: Dev traning 2016   intro to the web

Sacheen DhanjieSenior Developer @ Afrihost.com

Page 3: Dev traning 2016   intro to the web

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

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

Request / Response

Page 6: Dev traning 2016   intro to the web

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

Request/Response

Page 8: Dev traning 2016   intro to the web

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

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

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

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

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

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

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

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

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

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

ExamplesAfrihost Usage Example:• https://clientzone.afrihost.com/order/#/• Afrihost Mobile App

Page 19: Dev traning 2016   intro to the web

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