API Development - dotNet, C#, and RESTful APIs
Understanding what APIs are, how they work, and why they are central to modern software development
An API (Application Programming Interface) is a contract that allows two pieces of software to communicate with each other
// 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.
Returns HTML, CSS, and JavaScript — rendered visually by a browser
When a human is looking at the result in a browser
https://google.com returns a full HTML page
Returns structured data (JSON/XML) — consumed by code
When an app or another server needs to read the data
https://api.example.com/users returns [{id:1, name:"Alice"}]