Module 3 APIs Theory and Practical Implementation
Module 3 APIs Theory and Practical Implementation
Lecture Overview
• In this module, we'll explore the world of Application Programming Interfaces (APIs), understand
their significance in modern software development, and learn how to design and implement them
effectively. We'll dive into different types of APIs, with a focus on REST and GraphQL, and discuss
best practices for API design. In the practical segment, we'll implement APIs in Python using
FastAPI and learn how to call them using Postman.
Learning Objectives
By the end of this lecture, students will be able to:
• Understand the Fundamental Concepts of APIs
• Differentiate Between Types of APIs
• Apply Best Practices in API Design
• Develop APIs Using Python and FastAPI
• Call APIs Using Postman
What is an API?
What is an API?
An Application Programming Interface (API) is a set of rules and protocols that allows different
software applications to communicate with each other. APIs define the methods and data formats that
applications use to request and exchange data.
Fundamentals of APIs
• Interoperability
APIs enable different systems and applications to work together seamlessly.
• Reusability
Developers can leverage existing APIs to add functionality without building from scratch.
• Scalability
APIs allow services to scale by distributing workloads across different systems.
• Innovation
By exposing services through APIs, organizations encourage developers to build new applications on top of
their platforms.
Examples
Examples
Examples
Types of APIs
• REST API
• GraphQL
REST API
• REST api or RESTful api stands for Representational State Transfer
Application Programming Interface.
GraphQL
• GraphQL is a query language for APIs that allows clients to request exactly
the data they need, and nothing more.
Response of an API
• An API response is the data or result returned by the server
after it processes a request from the client. Responses usually
include information about the outcome of the request, such as
success or failure, along with any requested data.
Components of a Response
• Status Code
• Headers
• Body (Payload)
Status Code
• These help indicate the status of the request either success or
error
Headers
• Metadata about the response, such as content type or length
Body (Payload)
• Contains the actual data being returned by the server (if
applicable). This can be in formats like JSON, XML, or HTML.
JSON (JavaScript Object Notation)
• JSON is a lightweight data format that is easy for both humans
and machines to read and write. It is the most common format
used in modern APIs.
XML (eXtensible Markup Language)
• XML is a markup language that defines a set of rules for
encoding documents in a format that is both human-readable
and machine-readable. It is commonly used in older APIs and in
enterprise environments.
HTML (HyperText Markup Language)
• HTML is primarily used to structure content on the web but can
also be used as an API response format. It's less common for
data exchange compared to JSON or XML but might be used in
certain cases, such as returning error messages.
Let’s build an API