Guest User

Untitled

a guest
May 26th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. agreed on format used by people who are writing applications
  2.  
  3. dont have to know exactly how..
  4.  
  5. write program -- take input from stdin
  6. you have to parse it! into meaningful things!
  7.  
  8. if every program in the world had different parsing, then it is BAD.!!!!
  9. it would be difficult to write input for all of them
  10. program A wants THIS, program B wants THAT, etc etc
  11.  
  12. when info transferred over internet (instead of stdin), it is called a request
  13.  
  14. REST is a format agreed on (same as first line) by ppl who are smart and have written lots of format
  15. they think it's good format!
  16.  
  17. general format (OF REST) looks like this:
  18. {
  19. GET /hello.htm HTTP/1.1
  20. User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
  21. Host: www.tutorialspoint.com
  22. Accept-Language: en-us
  23. Accept-Encoding: gzip, deflate
  24. Connection: Keep-Alive
  25. }
  26.  
  27. first thing is: GET, POST, PUT, DELETE are the 4 major commands of REST
  28. second thing is the path (url): endpoint that is acceptable over the internet
  29. third thing is the protocol version (http 1.1)
  30. then we need headers (language response should be in, keep connection alive, etc)
  31. user-agent is which version of the client (in this case, it is mozilla browser!)
  32. after the request, you will get a response in
  33.  
  34. the response will look like
  35. {
  36. HTTP/1.1 200 OK
  37. Date: Mon, 27 Jul 2009 12:28:53 GMT
  38. Server: Apache/2.2.14 (Win32)
  39. Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
  40. Content-Length: 88
  41. Content-Type: text/html
  42. Connection: Closed
  43. <html>
  44. <body>
  45. <h1>Hello, World!</h1>
  46. </body>
  47. </html>
  48. }
  49.  
  50. first part is protocol version (just like request) (http 1.1)
  51. status message: 200 OK
  52. some are 404 not found, 403 forbidden, etc.
  53. more headers! (Date through Connection) are headers
  54. THE FORMAT HERE IS WHAT IS IMPORTANT!!!!
  55. THIS FORMAT IS DESCRIBED AT REST PROTOCOL
  56.  
  57. HTTP is a way of sending
  58. this is packet 2 of 10, 4 of 10, 1 of 10 (it might not be in order!)
  59. wait a minute! you forgot 5 of 10! Send again!
  60. this is the protocol called HTTP \(^__^)/
  61.  
  62. any message you send is broken down into packets like this^^^^^ above
  63.  
  64. http://api.example.com/resources/item17
  65.  
  66. IF YOU MAKE A REST REQUEST TO THIS URL/ENDPOINT
  67. the same exact url with a different verb can take a different action
  68. GET http __version
  69. all the headers you want
  70. server will say: This is a get request!
  71. ie: get me the content on that page
  72. POST
  73. means you want to send data to that endpoint
  74. this means:
  75. listener on button when you hit send
  76. going to make a POST request with that data
  77. when server gets post request
  78. let me check if this is valid!
  79. if so, i will insert the information into my database
  80. this data is sent in JSON format (standardized!)
  81. XML is an alternate to JSON (less popular now, more symbols, hard to read)
  82. JSON is very simple to read
  83. can embed one JSON document inside another document very easily
  84. EXAMPLE POST REQUEST { username: "esha" , password: "mypasswordyo" }
  85.  
  86. POST = new data
  87. PUT = update data
  88. GET = get data
  89. DELETE = delete data
  90.  
  91. "now open up your terminal and we are going to make a REST request" -esha senpai
  92.  
  93. when you code
  94. you'r goin to create a REST object
  95. with verb, with endpoint, with headers, etc.
  96. then you're going to call RESTObject.send() or s/th
  97. send means SEND THE REQUEST (request can be GET, POST, etc.)
  98. varies w/ language
  99.  
  100. THIS IS WHAT THE CODE MIGHT LOOK LIKE (for sending a rest request)
  101. {
  102. var request = new RestRequestObject("GET", "google.com", "/news", "HTTP/1.1"); //request is a RESTRequestObject
  103. var response = request.send(); //response is an object of type RESTResponseObject (or something)
  104. var responseJson = response.getJSON();
  105. print(responseJson);
  106. }
  107.  
  108. browser can send REST requests, terminal can send REST requests, language can send REST requests
  109.  
  110. OS (operating system) has a way of sending requests over the internet
  111. OS uses REST????
  112. no!!
  113. the OS can send packets
  114. so the browser/terminal (netcat)/language are not actually sending the request
  115. they are creating a gigantic string that is meant to be sent
  116. the OS cuts it into small packets and ACTUALLY does the sending!!
  117. yay OS!
  118. OS gets teh response (as a bunch of packets)
  119. and compiles it back into a gigantic string
  120. and gives it back to (netcat) terminal/etc.
  121. which will then parse the string and give you a response object of some sort
  122. which you will then do things with!
  123. all of these ways are all calling the underlying way of sending requests from the operating system
  124.  
  125. framework is just a layer built on top of the basic layers
  126. idk what that means tho...?
  127. programming for kids where they move blocks of code
  128. think NXT
  129. frameworks are essentially this for fancier higher level programming (scala stuff idk)
Add Comment
Please, Sign In to add comment