First Half

✅ Understanding HTTP
✅ HTTP Request Lifecycle
✅ Web Architecture Overview
✅ HTTP Request Structure
✅ HTTP Response Structure
✅ HTTP Request Example
✅ REST API 101
✅ API Versioning
✅ API Routes
✅ API Security Concepts
✅ API Consumption with Postman REST Client 🚀

Second Half

✅ Spec Driven Development
✅ Analyzing an API Spec
✅ Power of AI
✅ Workshop - Forge the Code 🧙🏼‍♀️🪄

Software Utilized

What is HTTP?

drawing

HTTP Versions

drawing

Key

Value

DNS Lookup

Resolve domain names (i.e., website addresses) to IP addresses, a unique number that identifies a device connected to the internet.

TCP 3-Way Handshake

Establishing a connection between client and server.

HTTP Request

Client sends an HTTP request.

HTTP Response

Server processes and returns the appropriate response.

Connection Close

Connections can be set to persistent, therefore reused (i.e., closed by client), or one time connections (i.e., closed by server).

drawing

HTTP Request Flow

drawing

Key

Value

Content Delivery Network (CDN)

A middleman cache (i.e., proxy cache) between a user and a server, often close to the user geographically, that stores copies of website content to reduce latency and improve load times.

Load Balancer

A device/software that distributes network traffic across multiple servers to improve efficiency and reliability.

drawing

URL Components

Base Syntax

https://www.wesellvehicles.com/vehicles/{make}/{model}?year={year}&exterior-color=navy&page-number=1&page-size=25

Example

https://www.wesellvehicles.com/vehicles/bmw/x3?year=2017&exterior-color=navy&page-number=1&page-size=25
  1. Scheme / Protocol
  1. Host / Domain
  1. Path
  1. Query Parameters

⭐️ Bonus question: What port does HTTP communicate over?

HTTP Methods

Methods are ways to request data from servers. They are in the form of verbs. Often referred to as CRUD operations.

Method

Usage

GET

Get data from the server

POST

Create a new resource on the server

PUT

Update an existing resource on the server

DELETE

Delete resource(s) on the server

HTTP Request Headers

Imagine sending a letter through the postal service. The envelope is the part that has your address and the person's address. That's like the HTTP headers, which have information about where the message is going and how it's being sent

Common Request Headers:

Example HTTP GET Request:

GET /weather?city=San+Francisco HTTP/1.1
Host: api.weather.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15
Accept: application/json

HTTP Body Structure

The body of the letter is the actual message you are sending inside the envelope. It could be words, pictures, or anything you're trying to communicate.

The body carries the payload that the client is sending to the server. This might include data in the form of JSON, XML, plain text, a file upload, etc.

Key points:

drawing

Status Codes

HTTP status codes are short messages your web browser and websites use to talk to each other when you're browsing the internet. They tell your browser what happened when it tried to load a webpage.

Here's a breakdown of the main categories:

1xx: Information

These codes let your browser know the request is being processed, but there's no final result yet. You rarely see these.

2xx: Success

Everything worked as expected!

3xx: Redirection

These codes mean the website you're trying to reach is sending you somewhere else.

4xx: Client Error

The problem is on your side (the browser or your request).

5xx: Server Error

These codes mean something went wrong on the website's server.

Response Headers and Body

The response body is the part of the response where the actual content you're looking for is sent back to you.

Headers

Example HTTP GET Response:

HTTP/1.1 200 OK
Date: Tue, 15 Sep 2024 19:20:00 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 354
Cache-Control: no-cache
ETag: "5f6cabc3-15e"

Body

{
    "city": "San Francisco",
    "temperature": 18.7,
    "description": "Partly cloudy",
    "humidity": 77,
    "wind_speed": 5.2,
    "forecast": [
        {
            "day": "Wednesday",
            "high": 19.4,
            "low": 13.2,
            "description": "Mostly sunny"
        },
        {
            "day": "Thursday",
            "high": 20.1,
            "low": 14.0,
            "description": "Clear skies"
        }
    ]
}

Key Points:

Do:

{
  data: [
    { ... },
    { ... }
  ]
}

Don't:

[
  { ... },
  { ... }
]
https://cat-fact.herokuapp.com/facts

drawing

> GET /facts HTTP/1.1
> Host: cat-fact.herokuapp.com
> User-Agent: curl/8.7.1
> Accept: */*

What is an API?

What is a RESTful API?

RESTful API Principles

1. Uniform Interface

2. Stateless

3. Cacheable

4. Client-Server

5. Layered System

6. Code on Demand (optional)

Why Version an API?

API Versioning Strategies

1. URI Path Versioning

The version number is included directly in the URL path:

GET /api/v1/users/123   (version 1 of the API)
GET /api/v2/users/123   (version 2 of the API)

2. Query Parameters Versioning

The version is passed as a query parameter in the request URL:

GET /api/users/123?version=1
GET /api/users/123?version=2

3. Header Versioning

The version number is specified in the HTTP headers, usually under a custom header:

GET /api/users/123
Accept: application/vnd.myapi.v1+json   (version 1)
Accept: application/vnd.myapi.v2+json   (version 2)

4. Embedded Versioning in Request/Response Body

The version number is embedded within the request or response body, instead of being part of the URL or headers:

{
  "version": "1.0",
  "data": { ... }
}

Pros and Cons?

API Deprecation Policies

Semantic Versioning

A versioning system that defines a structured, predictable format for assigning version numbers to software.

MAJOR.MINOR.PATCH

Where:

Example:

4.1.2

Every resource in a RESTful API has its own URL (web address).

Method

Route

Usage

GET

/menu

Check the menu

GET

/orders/123

Get the status of an order

POST

/orders

Place an order

PUT

/orders/123

Update an existing order

DELETE

/orders/123

Cancel an order

How would I delete all the orders?

Key Points

1. Authentication

Only authenticated users or systems can access the API (you are who you say you are).

drawing

2. Authorization

After authentication, authorization determines what resources a user or system can access (what do you have access to).

3. Encryption

Encrypting data in transit (via TLS/SSL) to protectg against "man-in-the-middle" attacks. Encrypted sometimes at rest to ensure data is unreadable if obtained.

4. Rate Limiting and Throttling

Controls the number of requests a client can make in a specific time frame to prevent abuse (e.g., DoS - Denial of Service - attacks).

5. Data Validation and Sanitization

Ensures that input data is valid, properly formatted, and free from malicious content (like SQL injection).

6. API Gateway

Acts as a proxy to manage, secure, and monitor API traffic.

7. Access Control

We are going to consume an API using the GET method.

Here are some good websites that will get you started when looking for free APIs to consume data from:

Let's take the following example:

drawing drawing

Parameter

Value

Method

GET

Base URL

https://yahoo-finance15.p.rapidapi.com

Path Parameters

/api/v2/markets/tickers

Query Parameters

page=1, type=STOCKS

Request Header

x-rapidapi-host: yahoo-finance15.p.rapidapi.com

API Key sent via Request Header

x-rapidapi-key: REDACTED

drawing

Ideal software development occurs in two distinct phases:

  1. The creation of a Spec
  2. Development of code to match the Spec

Spec Driven Development is the process of generating a concise spec that can be used to describe your application's interactions in a pragmatic way. In other words, the Spec is a blueprint for your application, detailing how the user interacts with it, rather than just expected behaviors/results. In order to be successful with Spec Driven Development, the Spec must be:

  1. Standardized: Use of a standard Spec related to the type of application you are building
  2. Consistent: The Spec should remain consistent throughout in operations, utlizing consistent design patterns
  3. Tested: Agile development of the Spec, incorporating repeated user feedback with long-term focus in mind
  4. Concrete: The creation of a complete, foundational Spec to be used for your application
  5. Immutable: Coding to the Spec without deviation
  6. Persistent: The Spec is not changed without strong reason and careful testing

Specs Available

We will be utilizing Swagger framework to design, produce, visualize, and consume our RESTful service. It provides a programming language-agnostic interface, which allows both humans and computers to discover and understand the capabilities of a service without requiring access to source code.

An OpenAPI spec is written in either JSON or YAML. We will be looking at a YAML spec for this demo.

Use the online swagger editor 👉🏼 editor.swagger.io or editor-next.swagger.io

There will be a sample pre-populated, which we will further break down.

For more docs, checkout: Swagger.io Docs

Who is Allie K. Miller?

Allie K. Miller is a leading AI expert, previously the Global Head of Machine Learning for Startups and Venture Capital at AWS. She helped scale AI innovation worldwide and was the youngest woman to develop an AI product at IBM. A recognized voice in tech, she advocates for diversity in AI, co-founding Girls of the Future and serving as a national ambassador for American Association for the Advancement of Science (AAAS). She holds an MBA from Wharton and frequently speaks on AI's future.

Proof is in the Pudding

LinkedIn Post LinkedIn Post

Follow her LinkedIn posts by clicking on "Follow" to get byte-sized bits of information 🙂

Kickoff with a ChatGPT Prompt

Select the correct GPT model to start out with!

given the following API endpoint: https://yahoo-finance15.p.rapidapi.com/api/v2/markets/tickers?page=1&type=STOCKS

lets say i pass in header x-rapidapi-host = yahoo-finance15.p.rapidapi.com and an API key which is passed in as a header like x-rapidapi-key = 9e87a2c143msh6b923

which resulted in the following json object:

{"meta":{"version":"v1.0","status":200,"copywrite":"https://apicalls.io","totalrecords":7008,"headers":{"symbol":"Symbol","name":"Name","lastsale":"Last Sale","netchange":"Net Change","pctchange":"% Change","marketCap":"Market Cap"}},"body":[{"symbol":"ABBV","name":"AbbVie Inc. Common Stock","lastsale":"$193.51","netchange":"-0.32","pctchange":"-0.165%","marketCap":"341,805,178,095"},{"symbol":"ASML","name":"ASML Holding N.V. New York Registry Shares","lastsale":"$814.00","netchange":"10.50","pctchange":"1.307%","marketCap":"320,245,280,894"},{"symbol":"NFLX","name":"Netflix, Inc. Common Stock","lastsale":"$722.26","netchange":"16.89","pctchange":"2.394%","marketCap":"309,968,434,830"},{"symbol":"KO","name":"Coca-Cola Company (The) Common Stock","lastsale":"$71.33","netchange":"-0.40","pctchange":"-0.558%","marketCap":"307,422,895,140"},{"symbol":"BAC","name":"Bank of America Corporation Common Stock","lastsale":"$39.45","netchange":"-0.42","pctchange":"-1.053%","marketCap":"306,115,328,943"},{"symbol":"MRK","name":"Merck & Company, Inc. Common Stock (new)","lastsale":"$114.96","netchange":"-0.67","pctchange":"-0.579%","marketCap":"291,401,678,508"},{"symbol":"CVX","name":"Chevron Corporation Common Stock","lastsale":"$147.45","netchange":"-0.09","pctchange":"-0.061%","marketCap":"269,673,828,312"},{"symbol":"SAP","name":"SAP  SE ADS","lastsale":"$230.93","netchange":"0.49","pctchange":"0.213%","marketCap":"269,548,205,902"},{"symbol":"CRM","name":"Salesforce, Inc. Common Stock","lastsale":"$270.44","netchange":"6.23","pctchange":"2.358%","marketCap":"258,540,640,000"},{"symbol":"AMD","name":"Advanced Micro Devices, Inc. Common Stock","lastsale":"$158.32","netchange":"1.57","pctchange":"1.002%","marketCap":"256,238,045,700"},{"symbol":"TM","name":"Toyota Motor Corporation Common Stock","lastsale":"$183.53","netchange":"-1.87","pctchange":"-1.009%","marketCap":"247,291,479,267"},{"symbol":"AZN","name":"AstraZeneca PLC American Depositary Shares","lastsale":"$76.87","netchange":"-0.27","pctchange":"-0.35%","marketCap":"238,341,067,572"},{"symbol":"NVS","name":"Novartis AG Common Stock","lastsale":"$116.42","netchange":"0.05","pctchange":"0.043%","marketCap":"237,966,436,650"},{"symbol":"BABA","name":"Alibaba Group Holding Limited American Depositary Shares each representing eight Ordinary share","lastsale":"$97.19","netchange":"7.10","pctchange":"7.881%","marketCap":"236,525,556,155"},{"symbol":"TMUS","name":"T-Mobile US, Inc. Common Stock","lastsale":"$201.44","netchange":"-1.02","pctchange":"-0.504%","marketCap":"235,036,975,608"},{"symbol":"TMO","name":"Thermo Fisher Scientific Inc Common Stock","lastsale":"$611.88","netchange":"1.53","pctchange":"0.251%","marketCap":"233,735,446,924"},{"symbol":"PEP","name":"PepsiCo, Inc. Common Stock","lastsale":"$169.92","netchange":"-2.19","pctchange":"-1.272%","marketCap":"233,397,422,208"},{"symbol":"ADBE","name":"Adobe Inc. Common Stock","lastsale":"$524.07","netchange":"-3.80","pctchange":"-0.72%","marketCap":"232,372,638,000"},{"symbol":"LIN","name":"Linde plc Ordinary Shares","lastsale":"$479.35","netchange":"1.99","pctchange":"0.417%","marketCap":"228,890,936,981"},{"symbol":"CCZ","name":"Comcast Holdings ZONES","lastsale":"$58.89","netchange":"1.64","pctchange":"2.865%","marketCap":"228,051,620,578"},{"symbol":"SHEL","name":"Shell PLC American Depositary Shares (each representing two (2) Ordinary Shares) ","lastsale":"$69.41","netchange":"0.33","pctchange":"0.478%","marketCap":"217,305,988,853"},{"symbol":"MCD","name":"McDonald's Corporation Common Stock","lastsale":"$300.27","netchange":"1.21","pctchange":"0.405%","marketCap":"215,396,656,777"},{"symbol":"ACN","name":"Accenture plc Class A Ordinary Shares (Ireland)","lastsale":"$339.62","netchange":"0.41","pctchange":"0.121%","marketCap":"212,837,532,697"},{"symbol":"CSCO","name":"Cisco Systems, Inc. Common Stock (DE)","lastsale":"$52.52","netchange":"0.33","pctchange":"0.632%","marketCap":"209,593,391,381"},{"symbol":"GE","name":"GE Aerospace Common Stock","lastsale":"$189.66","netchange":"0.99","pctchange":"0.525%","marketCap":"205,650,427,295"}]}

can you create a RESTful API spec for me that creates the following endpoint: 

GET /stocks 

which takes in a query parameter named "page" that takes an integer and the result is the same object as seen above

Follow-up prompts:

Enter Claude.ai

Claude AI is a family of AI models developed by Anthropic, a company founded by former OpenAI researchers. The model is named after Claude Shannon, the father of information theory.

Does require a paid subscription to take advantage of the "Use a project" functionality: Claude.ai

drawing

Everything after this point will be done on the fly! Nothing prepped to mimic real-world scenario!

drawing

drawing drawing