Advertisement
yo2man

Lesson 16: What is REST API for dummies:

Sep 11th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. Lesson 16: What is REST API for dummies: https://www.youtube.com/watch?v=7YcW25PHnAA <- Prepare to take notes and learn cuz he goes through it fast and succiently and you learn ALOT in those 8:30 mins.
  2.  
  3. Notes to self:
  4.  
  5. API stands for Application Programming Interface, it basically allows an application to talk to another. There are a lot of different kinds of APIs.
  6.  
  7. When people talk about Twitter's API, Google's API, etc they are talking about REST API.
  8. REST = REpresentational State Transfer.
  9.  
  10.  
  11.  
  12. basically REST API works very much the same way a website does.
  13. You make a call from a Client to the Server and get back data over the HTTP protocol.
  14.  
  15. For example: https://graph.facebook.com/ is an api. What you get back is JSON (JavaScript Object Notation).
  16. You retrieve the JSON array for information like how many LIKES the facebook page has:
  17.  
  18. "likes" : 81768558  <-- to get that information into your android program, use the key ("likes")
  19.  
  20. The parameter aka stuff that you want can be set like this https://graphs.facebook.com/youtube?fields=id,name,likes. and it will narrow down the JSON to show:
  21. {  
  22. "id": "12343",
  23. "name": "YouTube",
  24. "likes": 81793958
  25. }
  26.  
  27.  
  28.  
  29. Besides getting data, you can also write data to APIs.
  30.  
  31. HTTP request methods:
  32. GET and POST
  33.  
  34. normal web browser doesn't allow you to put POST in the body of a request but you can install POSTMAN -REST Client extension that does: https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en
  35.  
  36. With POSTMAN you can make more complex api requests. for example you can choose any one of the GET,POST,PUT,PATCH,DELETE,COPY,HEAD, etc requests.
  37.  
  38. Let's use POSTMAN to send a tweet out using Twitter API.
  39.  - but first we need authentication. w/o authentication, I would be able to send tweets out from your account and you from mine and impersonate me. That would be horrible :(.
  40.  
  41.     - a lot of these Big online websites are using OAUTH, or OAUTH2. Basically you are getting credentials. like login and password, except they are called Client ID and Client Secret. And you are using your credentials to exchange for an "access token" and you pass that "access token" to twitter so twitter knows its you.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement