Group Assignment: Deepdive into APIs
For the following tasks, create a live code example for the task implementation and, additionally, create a short Word document highlighting and documenting your approach so that your peers can use this document as a reference when implementing the same on their own. The presentation should not be longer than 8 minutes. You have 80 minutes plus 10 minutes break of preparation time.
Task 1: API Rate Limiting & Authentication
Objective: Deepen understanding of security mechanisms in REST APIs.
- Theory: Research why rate limiting and authentication are important for REST APIs. What are common methods (e.g., API keys, OAuth, JWT)?
- Practice:
- Create a REST API with a protected route.
- Implement API rate limiting (e.g., using
express-rate-limitin Node.js orFlask-Limiterin Python). - Add simple authentication (e.g., JWT or API key).
- Presentation: Explain your approach, show code examples, and discuss the pros and cons of the implemented methods.
Task 2: Caching in REST APIs
Objective: Understand the importance of caching for API performance.
- Theory: Research different caching strategies (client-side caching, proxy caching, server-side caching with Redis or Memcached).
- Practice:
- Create a REST API with a route that loads data from a slow source (e.g., a file or an external API).
- Implement server-side caching with Redis or a similar tool.
- Compare response times with and without caching.
- Presentation: Explain how your caching works and show performance improvements with measurements.
Task 3: Error Handling & Logging in REST APIs
Objective: Learn the importance of structured error handling and logging for robust APIs.
- Theory: Research best practices for API error handling (HTTP status codes, exception handling, error logging).
- Practice:
- Create a REST API with multiple endpoints.
- Implement robust error handling (e.g., try-catch blocks, error classes, specific HTTP status codes).
- Add logging (e.g., using Winston in Node.js or Python’s logging module).
- Presentation: Demonstrate how your error handling works, show log examples, and discuss best practices.
Task 4: API Monitoring & Health Checks
Objective: Learn about monitoring tools to track API performance and availability.
- Theory: Research methods to monitor APIs (health check endpoints, tools like Prometheus, Grafana, or the ELK stack).
- Practice:
- Create a REST API with a health check endpoint (
/health). - Integrate your API with a monitoring tool (e.g., Prometheus + Grafana or a simple logging solution).
- Simulate API failures and demonstrate how monitoring helps.
- Create a REST API with a health check endpoint (
- Presentation: Showcase the implemented solutions and explain how monitoring tools are used.
Task 5: Asynchronous Processing with Message Queues
Objective: Understand how asynchronous processing works with message queues.
- Theory: Research why asynchronous processing is important. What are common message queues (RabbitMQ, Kafka, Redis Streams)?
- Practice:
- Create a REST API that triggers a time-consuming task (e.g., image processing or large database queries).
- Decouple processing using a message queue (e.g., RabbitMQ or Redis Queue).
- Implement a separate worker process to handle queued jobs.
- Presentation: Explain your concept, show the code, and compare performance with and without a message queue.
Task 6: API Versioning & Documentation
Objective: Learn how to version and document APIs.
- Theory: Research API versioning methods (URL versioning, header versioning, media type versioning).
- Practice:
- Create a REST API with at least two versions (
v1andv2). - Document your API using Swagger/OpenAPI.
- Create a small frontend or demo to show the differences between
v1andv2.
- Create a REST API with at least two versions (
- Presentation: Showcase your versioning approach, present the documentation, and discuss the benefits.