Web API & Flask Assignment
Q1: What is a Web API?
A Web API is an interface that allows communication and data exchange between
software applications over the web using HTTP.
Q2: How does a Web API differ from a web service?
Web APIs are broader and can use various protocols like HTTP, WebSocket, etc.
Web services specifically follow SOAP or REST architectures.
Q3: Benefits of using Web APIs in software development:
Simplifies integration between systems.
Promotes modularity and reuse of services.
Enables cross-platform communication.
Q4: Difference between SOAP and RESTful APIs:
SOAP: Protocol-based, uses XML, strict standards, and provides built-in error
handling.
REST: Architectural style, supports multiple formats (e.g., JSON, XML),
lightweight, and stateless.
Q5: What is JSON and how is it commonly used in Web APIs?
JSON (JavaScript Object Notation) is a lightweight data-interchange format
commonly used to transmit structured data between clients and servers in Web
APIs.
Q6: Popular Web API protocols other than REST:
GraphQL.
gRPC.
OData.
Q7: Role of HTTP methods in Web API development:
GET: Retrieve data.
POST: Create new resources.
PUT: Update existing resources.
DELETE: Remove resources.
Q8: Purpose of authentication and authorization in Web APIs:
Authentication: Verifies the user's identity.
Authorization: Determines the user's access rights.
Q9: Handling versioning in Web API development:
Use strategies like:
Adding version numbers in URLs (e.g., /v1/resource).
Using headers for version control (e.g., Accept-Version).
Q10: Main components of an HTTP request and response in Web APIs:
Request: Method, URL, headers, and body.
Response: Status code, headers, and body.
Q11: Concept of rate limiting in Web APIs:
Rate limiting restricts the number of API requests a client can make within a time
frame to prevent abuse.
Q12: Handling errors and exceptions in Web API responses:
Use meaningful HTTP status codes.
Include error messages and details in the response body.
Q13: Statelessness in RESTful Web APIs:
Each request is independent and contains all the information needed to process
it, without relying on server-side state.
Q14: Best practices for designing and documenting Web APIs:
Use consistent naming conventions for endpoints.
Provide clear documentation using tools like Swagger or Postman.
Follow REST principles and versioning strategies.
Q15: Role of API keys and tokens in securing Web APIs:
API keys and tokens authenticate requests and ensure secure access to the API.
Q16: What is REST, and what are its key principles?
REST is an architectural style based on stateless communication, resource-based
URIs, and standard HTTP methods.
Q17: Difference between RESTful APIs and traditional web services:
RESTful APIs are lightweight, flexible, and support multiple formats.
Traditional web services often rely on SOAP with strict XML schemas.
Q18: Main HTTP methods used in RESTful architecture and their purposes:
GET: Retrieve resources.
POST: Create resources.
PUT: Update resources.
DELETE: Remove resources.
Q19: Statelessness in RESTful APIs:
Servers do not retain client state between requests, enabling scalability and
simplicity.
Q20: Significance of URIs in RESTful API design:
URIs uniquely identify resources, forming the backbone of RESTful API design.
Q21: Role of hypermedia in RESTful APIs and HATEOAS:
Hypermedia (links in responses) guides clients on how to interact with resources
dynamically, following the HATEOAS principle.
Q22: Benefits of RESTful APIs over other architectural styles:
Lightweight and scalable.
Easy to implement and maintain.
Supports multiple formats (e.g., JSON, XML).
Q23: Concept of resource representations in RESTful APIs:
Resources can have multiple representations (e.g., JSON, XML), allowing
flexibility in communication.
Q24: How REST handles communication between clients and servers:
Uses stateless HTTP requests with clear methods and resource-based URIs.
Q25: Common data formats used in RESTful API communication:
JSON, XML, YAML, and plain text.
Q26: Importance of status codes in RESTful API responses:
Status codes provide feedback about the result of a request, e.g.,
200: Success.
404: Resource not found.
500: Server error.
Q27: Process of versioning in RESTful API development:
Add versioning through URI, headers, or query parameters to maintain backward
compatibility.
Q28: Ensuring security in RESTful API development:
Use HTTPS.
Authenticate using API keys, OAuth, or JWT.
Validate inputs to prevent injection attacks.
Q29: Best practices for documenting RESTful APIs:
Use tools like Swagger or OpenAPI.
Include endpoint details, parameters, and sample requests/responses.
Q30: Considerations for error handling in RESTful APIs:
Use clear error codes and messages.
Follow consistent response formats.
Log errors for debugging.
Q31: What is SOAP, and how does it differ from REST?
SOAP (Simple Object Access Protocol) is a protocol that uses XML for structured
messaging, while REST is an architectural style.
Q32: Structure of a SOAP message:
Envelope: Defines the message structure.
Header: Metadata.
Body: Contains the message.
Fault: Error details (if any).
Q33: How SOAP handles communication between clients and servers:
SOAP uses XML messages exchanged over protocols like HTTP, SMTP, or TCP.
Q34: Advantages and disadvantages of SOAP-based web services:
Advantages: High security, built-in error handling.
Disadvantages: Heavyweight, complex, slower compared to REST.
Q35: How SOAP ensures security in web service communication:
Relies on WS-Security standards for encryption, authentication, and integrity.
Q36: What is Flask, and what makes it different from other web frameworks?
Flask is a lightweight Python web framework with minimal dependencies, making
it flexible and easy to use compared to larger frameworks like Django.
Q37: Basic structure of a Flask application:
Import Flask.
Create a Flask app instance.
Define routes using decorators.
Run the app.
Code :
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, Flask!"
if __name__ == '__main__':
app.run(debug=True)
Q38: How to install Flask on your local machine:
Use pip:
pip install flask
Q39: Concept of routing in Flask:
Routing maps URLs to specific functions in your Flask app using decorators like
@app.route().
Q40: What are Flask templates, and how are they used in web development?
Flask templates are HTML files that dynamically render content using Jinja2
templating. Example:
<h1>Hello, {{ name }}!</h1> .