Introduction to APIs [22nd Dec 2022]

I made changes to the notes from the github link below to make my own notes

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

Unit 1 - What is an API

In this unit we'll define what an API(Application Programming Interface) is and why you should use them.

Video 1 - Welcome

๐Ÿ‘‹ Hello and welcome to the course and your notes! Make sure you check this area out often!

๐Ÿ‘€ - Beginner content

๐Ÿ“š - Designing API Content

Video 2 - Defining Interface

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.

๐Ÿ“š - Learn more

Media Player APIs

Don't worry about understanding it, just appreciate their complexity

Video 3 - Defining API

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.

๐Ÿ“š - Learn more

Video 4 - Remote APIs

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.

Video 5 - How the web works

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.

Video 6 - RESTful API Constraint Scavenger Hunt

Unit 2 - Exploring APIs

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:

  1. Client-Server Architecture
  2. Statelessness
  3. Layered System
  4. Cacheability
  5. Uniform Design
  6. Code on Demand

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:

  1. The request to the server has to include resource identifier.
  2. The response the server returns include enough information so the client can modify the resource.
  3. Each request to API has all info server need to perform the request, and each response server returns has all info client needs to understand it.
  4. Something about Hypermedia as the engine of application state, which I quite didn't understand. You can watch a video on it here.

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

Video 1 - Exploring an API online

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).

๐Ÿ‘€ - Explore

API List provides categories and a powerful search feature.

Video 2 - Using an API from the command line

cURL

Mac OS
Using Homebrew
      brew install curl

    
Download

โฌ‡๏ธ - Download cURL for MacOSX

Windows

โฌ‡๏ธ - 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

    

๐Ÿ“š - Learn More

Video 3 - Using Postman to explore APIs

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

Video 4 - Please please Mr. Postman

โฌ‡๏ธ - Many wonderful API Collections can be downloaded for exploration in the Postman API Network

๐Ÿ“š - Learn more

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).

Video 5 - Using Helper Libraries (JavaScript)

To use the Twilio Node Helper Library

      npm install twilio

    

๐Ÿ“š - Learn More

Video 6 - Using Helper Libraries (Python)

To use the Twilio Python Helper Library

      pip install twilio

    

Unit 3 - Using APIs

Video 1 - Introducing the project

๐Ÿ“š - Learn more

Video 2 - Flask app

โš ๏ธ 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

๐Ÿ“š - Learn more

Video 3 - Dealing with API Limits

๐Ÿ“š - Learn more

Video 4 - JavaScript Single Page Application

โš ๏ธ 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

๐Ÿ“š - Learn more

Video 5 - Moar JavaScript and Recap

Video 6 - Review

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 ๐Ÿ’ช๐Ÿš€!

@craigsdennis

PS. If you want to keep on learning for free, I can't recommend the video game TwilioQuest ๐ŸŽฎ enough.

๐Ÿ“š - Learn more