Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- agreed on format used by people who are writing applications
- dont have to know exactly how..
- write program -- take input from stdin
- you have to parse it! into meaningful things!
- if every program in the world had different parsing, then it is BAD.!!!!
- it would be difficult to write input for all of them
- program A wants THIS, program B wants THAT, etc etc
- when info transferred over internet (instead of stdin), it is called a request
- REST is a format agreed on (same as first line) by ppl who are smart and have written lots of format
- they think it's good format!
- general format (OF REST) looks like this:
- {
- GET /hello.htm HTTP/1.1
- User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
- Host: www.tutorialspoint.com
- Accept-Language: en-us
- Accept-Encoding: gzip, deflate
- Connection: Keep-Alive
- }
- first thing is: GET, POST, PUT, DELETE are the 4 major commands of REST
- second thing is the path (url): endpoint that is acceptable over the internet
- third thing is the protocol version (http 1.1)
- then we need headers (language response should be in, keep connection alive, etc)
- user-agent is which version of the client (in this case, it is mozilla browser!)
- after the request, you will get a response in
- the response will look like
- {
- HTTP/1.1 200 OK
- Date: Mon, 27 Jul 2009 12:28:53 GMT
- Server: Apache/2.2.14 (Win32)
- Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
- Content-Length: 88
- Content-Type: text/html
- Connection: Closed
- <html>
- <body>
- <h1>Hello, World!</h1>
- </body>
- </html>
- }
- first part is protocol version (just like request) (http 1.1)
- status message: 200 OK
- some are 404 not found, 403 forbidden, etc.
- more headers! (Date through Connection) are headers
- THE FORMAT HERE IS WHAT IS IMPORTANT!!!!
- THIS FORMAT IS DESCRIBED AT REST PROTOCOL
- HTTP is a way of sending
- this is packet 2 of 10, 4 of 10, 1 of 10 (it might not be in order!)
- wait a minute! you forgot 5 of 10! Send again!
- this is the protocol called HTTP \(^__^)/
- any message you send is broken down into packets like this^^^^^ above
- http://api.example.com/resources/item17
- IF YOU MAKE A REST REQUEST TO THIS URL/ENDPOINT
- the same exact url with a different verb can take a different action
- GET http __version
- all the headers you want
- server will say: This is a get request!
- ie: get me the content on that page
- POST
- means you want to send data to that endpoint
- this means:
- listener on button when you hit send
- going to make a POST request with that data
- when server gets post request
- let me check if this is valid!
- if so, i will insert the information into my database
- this data is sent in JSON format (standardized!)
- XML is an alternate to JSON (less popular now, more symbols, hard to read)
- JSON is very simple to read
- can embed one JSON document inside another document very easily
- EXAMPLE POST REQUEST { username: "esha" , password: "mypasswordyo" }
- POST = new data
- PUT = update data
- GET = get data
- DELETE = delete data
- "now open up your terminal and we are going to make a REST request" -esha senpai
- when you code
- you'r goin to create a REST object
- with verb, with endpoint, with headers, etc.
- then you're going to call RESTObject.send() or s/th
- send means SEND THE REQUEST (request can be GET, POST, etc.)
- varies w/ language
- THIS IS WHAT THE CODE MIGHT LOOK LIKE (for sending a rest request)
- {
- var request = new RestRequestObject("GET", "google.com", "/news", "HTTP/1.1"); //request is a RESTRequestObject
- var response = request.send(); //response is an object of type RESTResponseObject (or something)
- var responseJson = response.getJSON();
- print(responseJson);
- }
- browser can send REST requests, terminal can send REST requests, language can send REST requests
- OS (operating system) has a way of sending requests over the internet
- OS uses REST????
- no!!
- the OS can send packets
- so the browser/terminal (netcat)/language are not actually sending the request
- they are creating a gigantic string that is meant to be sent
- the OS cuts it into small packets and ACTUALLY does the sending!!
- yay OS!
- OS gets teh response (as a bunch of packets)
- and compiles it back into a gigantic string
- and gives it back to (netcat) terminal/etc.
- which will then parse the string and give you a response object of some sort
- which you will then do things with!
- all of these ways are all calling the underlying way of sending requests from the operating system
- framework is just a layer built on top of the basic layers
- idk what that means tho...?
- programming for kids where they move blocks of code
- think NXT
- frameworks are essentially this for fancier higher level programming (scala stuff idk)
Add Comment
Please, Sign In to add comment