API beginner course by FreeCodeCamp: Youtube Video GitHub link.
Tip: For signups, you can have infinite mail idโs by using name+site@gmail.com
In this unit we'll define what an API(Application Programming Interface) is and why you should use them.
๐ Hello and welcome to the course and your notes! Make sure you check this area out often!
Interface Interface is the thing that you interact with and control the way a device works. The process happening inside a device is abstracted by the interface. They are also used in GUIs. Like a play button in a music player. Interfaces abstract the implementation of the process.
Don't worry about understanding it, just appreciate their complexity
In the context of APIs, the word Application refers to any software with a distinct function. Interface can be thought of as a contract of service between two applications. This contract defines how the two communicate with each other using requests and responses.
Like the UI is made for the user, the API is made for the application programmer.
Using APIโs gives us many advantages. One of them is computational power. Doing some of the tasks a remote API does, like, searching for a song playing in real time, using google translate to translate something in real time using a camera. To do these things, you will need to have a database of all the songs or words on your device. But, with a remote API, you donโt need to.
URL โ Universal Resource Locator, URI is a super set of URLs, I in URI is Identifier.
When clicking a link on your browser, the browser which acts as a client to the server, will send a HTTP URI GET request to the server, for this request, the server will send a response, whose body will be in HTTP(Hyper Text Transfer Protocol).
Resource in URL can be used to describe anything. In an example of a bookstore website, a book shows information like its author, which is also a resource. If you click on the author, it will show a collection of books by that author. You may also see a group of reviews from fans, which is also a resource. If you click on a fan, you will see a collection of books and authors they like.
REST โ Representational State Transfer. This type of remote API is one of the many used but, it is the most used one. This course focuses on REST APIโs. For an API to be RESTful, these constraints should be followed:
An API's definition is simply a contract which defines how two applications should communicate. This communication happens between client and server, so it is client-server communication.
Stateless means it doesnโt remember anything happening in a session, so if you want to maintain state like login in a session, you must do it in every session individually using headers.
A layered system is when an API calls another API. This is done to make the API more efficient. Like, if you want to get the weather of a city, you can use an API which calls another API to get the weather of that city.
A RESTful API should support caching. If you have any file which is consuming more storage, you should be careful to conserve resources by not calling that file again and again. So, you can just store the file and check if it is modified. If it is, we should call for that file, if it isnโt, we can just call the stored file.
(The information on uniform design is taken from here.) The result of the uniform design is that requests from different clients look the same. Different clients means chrome browser, android app, linux server, python script or anything else. Uniform design has four more constraints in it. They are:
The code on demand constraint is optional. An API can be RESTful even without this. The client can request code from the server, and then the response from the server will contain some code, usually in the form of a script, when the respnse is in HTML. The client can then execute that code.
The body of the reply you get when you send a http request is in JSON, which is JavaScript Object Notation. It provides a way to structure and nest your data. Every programming language will have ways to turn a JSON string into a native object. You can also specify a Content Type in your request.
HTTP Verbs used in REST APIs: CRUD GET Read POST Create PUT Update PATCH Update DELETE Delete
This course uses Spotify and Twilio APIs. Using a Twilio API, you can send a text message from a number to your registered phone number (one of many things it can do).
56oDRnqbIiwx4mymNEv7dS
API List provides categories and a powerful search feature.
brew install curl
โฌ๏ธ - Download cURL for MacOSX
โฌ๏ธ - Download cURL for Windows
NOTE: If you are running PowerShell, delete the curl
alias for Invoke-WebRequest
by
adding the following command to your profile
(C:\Users\<username>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1)
:
Remove-Item alias:curl
form-urlencoded
search for "Use for submitting web forms)
This course is also using Postman, which will also be useful for the APISEC course also.
Now, you can create a folder to save your API requests, you should get the request URL from the CURL, or from the API. Then for the authentication part, create variables for the username and password and use them to avoid sharing sensitive information with your team.
โฌ๏ธ - Download Postman
The Twilio Messages API URL is:
https://api.twilio.com/2010-04-01/Accounts/<Your Account SID Here>/Messages.json
Make sure to replace that SID
with your Account SID which can be found in the Twilio console
โฌ๏ธ - Many wonderful API Collections can be downloaded for exploration in the Postman API Network
The next part is about using JavaScript and Python to write a code which can print the latest message sent or send a new message. This is done by downloading helper libraries of an API in your preferred language. These helper libraries are also called as SDKs(Software Development Kit).
To use the Twilio Node Helper Library
npm install twilio
To use the Twilio Python Helper Library
pip install twilio
โ ๏ธ Several students have reported that cloning sets up a default Glitch application. If this happens to you, in the Glitch app that is created choose "Tools >> Extras >> Git Import and Export >> Import from GitHub" when prompted enter "craigsdennis/intro-to-apis-node" or "craigsdennis/intro-to-apis-flask"
Complimentr Flask GitHub repository is located at
https://github.com/craigsdennis/intro-to-apis-flask.git
โ ๏ธ Several students have reported that cloning sets up a default Glitch application. If this happens to you, in the Glitch app that is created choose "Tools >> Extras >> Git Import and Export >> Import from GitHub" when prompted enter "craigsdennis/intro-to-apis-node" or "craigsdennis/intro-to-apis-flask"
Complimentr Node.js GitHub repository is located at
https://github.com/craigsdennis/intro-to-apis-node.git
I built a little Twilio application using Studio and some APIs to gather your feedback.
Please text FEEDBACK
to me at (503) 461-5537 and let me know what you
thought about this course! (You can also call if that's your jam)
๐ Thanks for hanging out! ๐ Keep me updated on your journey ๐ช๐!
PS. If you want to keep on learning for free, I can't recommend the video game TwilioQuest ๐ฎ enough.