APIs
APIs
APIs
Web APIs: These are APIs that are accessed over the web, using HTTP requests and responses. Web APIs
are typically built using REST (Representational State Transfer) architecture, which uses HTTP methods
(such as GET, POST, PUT, and DELETE) to perform operations on resources.
SOAP APIs: SOAP (Simple Object Access Protocol) is an older, XML-based protocol for building APIs.
SOAP APIs are less common than web APIs, but they are still used in some legacy systems.
GraphQL APIs: GraphQL is a newer API technology that allows clients to request only the data they
need, in a structured format. GraphQL APIs are gaining popularity due to their flexibility and efficiency.
Lesson 3: API Providers and Consumers
In the API world, there are two main roles: API providers and API consumers.
API providers are the ones who create the API, define its endpoints and resources, and provide
documentation and access to it.
API consumers are the ones who use the API, sending requests and receiving responses to retrieve or
modify data.
API providers can be companies like Facebook, Google, or Amazon, which offer APIs for their
services. API consumers can be other companies or developers who use those APIs to build their
own applications.
To implement this API, we can use a web framework like Flask (in Python) or Express (in
Node.js). Here's an example of how to implement the GET /api/books endpoint in Flask:
pythonCopy code
from flask import Flask, jsonify app = Flask(__name__) books = [ { "id" : 1 , "title" : "The Great Gatsby" ,
"author" : "F. Scott Fitzgerald" }, { "id" : 2 , "title" : "To Kill a Mockingbird" , "author" : "Harper Lee" }, { "id" : 3 ,
"title" : "1984" , "author" : "George Orwell" } ] @app.route('/api/books') def get_books (): return jsonify(books)