Week 9 - Networking and APIs

Introduction to Networking

Client Server Model

TCP/IP Protocol

HTTP Protocol

URL Format

Web APIs

API Testing Tools

Using APIs

Practice

Assignment

Core program

What are Web APIs?

An API stands for Application Programming Interface. A Web API is implemented by a web application server through which it makes it services available to client applications.

Think of an API as a menu in a restaurant, and the web server is the kitchen.

A Web API (or Web Service API) is simply an API that is accessible over the HTTP protocol, the same protocol used for viewing websites. It allows different software applications to communicate with each other over the internet.

Here is a quick intro into APIs, check out the video below (3:56 min):

https://www.youtube.com/watch?v=bxuYDT-BWaI

Public vs Private APIs

There are 2 different types of APIs: public and private APIs.

An API is public when software companies publish parts of their software to be freely used by developers from the outside world. If you were to integrate the Facebook API as a login system in your application, you would be using their API as a public API.

Conversely, there are also private APIs: software companies that grant access to parts of their backend applications to internal developers only, in order to develop new services to be used either internally or for the outside world.

In reality, there are way more private than public APIs. This is because it's usually in the company's best interest to keep their code base hidden from the public eye: it would be like giving your secret recipe away for free.

Keep this in mind: in the real world programming is only a means to serving a business end. In this course you're learning how to program, to make nice-looking, well-functioning applications. However, this is always done within a business context. This is to say: does this software lead to making more money/gaining more popularity/or the achievement of any other business goal?

Important API Concepts

The Core Purpose: Communication

The primary goal of a Web API is to allow a client (like your JavaScript application) to access data or trigger actions on a remote server.

Standardized Exchange: Request and Response

Web API communication is always a two-part standardized cycle:

Step Component Description
1. The Request Client sends data to Server Your application constructs a request, which contains:

The Standard Data Format: JSON

Nowadays, the vast majority of modern Web APIs use JSON (JavaScript Object Notation) as the format for exchanging data in the request and response bodies. (Before JSON took over, another format called XML was commonly used on the web.)

JSON is a human-readable, lightweight format that is native to JavaScript, making it the perfect choice for API development and consumption using tools like fetch.

Example of a JSON Response Body:

{
  "user_id": 101,
  "first_name": "Alex",
  "is_active": true,
  "orders": [
    { "id": 5001, "item": "Widget" },
    { "id": 5002, "item": "Gadget" }
  ]
}

REST (Representational State Transfer)

When you hear the term web API, it is almost always referring to a RESTful API.

Specific URLs at which an API responds to HTTP requests are called endpoints. The table below gives an example of the endpoints of a RESTful API.

Action HTTP Method Endpoint Parameter (id)
Get a list of books GET /books
Get a single book GET /books/{id} 42
Create a new book POST /books
Update book 42 PUT or PATCH /books/{id} 42
Delete book 42 DELETE /books/{id} 42

https://www.youtube.com/watch?v=-mN3VyJuCjM

https://www.youtube.com/watch?v=tkfVQK6UxDI


The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 **

CC BY-NC-SA 4.0 Icons

*https://hackyourfuture.net/*