Level Two

Level Two

API Development - dotNet, C#, and RESTful APIs

Select a week

What is an API?

Understanding what APIs are, how they work, and why they are central to modern software development

Week 0

Topics

What is an API?

An API (Application Programming Interface) is a contract that allows two pieces of software to communicate with each other

Key Points

  • API stands for Application Programming Interface
  • An API defines what requests can be made, how to make them, and what responses to expect
  • APIs let different applications talk to each other without knowing each other's internals
  • A Web API communicates over HTTP — the same protocol browsers use to load web pages
  • APIs return structured data (usually JSON) rather than HTML pages

Interactive Code Examples

// Using the browser's built-in fetch() to call a public API
// This API returns a random joke as JSON
fetch("https://official-joke-api.appspot.com/random_joke")
  .then(response => response.json())
  .then(data => {
    console.log(data.setup);    // "Why don't scientists trust atoms?"
    console.log(data.punchline); // "Because they make up everything!"
  });

// The API sends back JSON like this:
// {
//   "id": 1,
//   "type": "general",
//   "setup": "Why don't scientists trust atoms?",
//   "punchline": "Because they make up everything!"
// }

💡 Explanation: fetch() sends an HTTP GET request to a URL. The API at that URL returns JSON data. response.json() parses the JSON text into a JavaScript object. No account or setup required for public APIs.

API vs Website

Website

Returns HTML, CSS, and JavaScript — rendered visually by a browser

When to use:

When a human is looking at the result in a browser

Example:

https://google.com returns a full HTML page

Web API

Returns structured data (JSON/XML) — consumed by code

When to use:

When an app or another server needs to read the data

Example:

https://api.example.com/users returns [{id:1, name:"Alice"}]