Backend Developer Training - Week Eight
Document Details
Uploaded by Deleted User
Tags
Summary
This TechCrush presentation covers backend development, including RESTful API concepts, design criteria, and best practices for project folder structuring. The document provides an overview of key aspects like HTTP methods, status codes, pagination, versioning, and consistent error handling.
Full Transcript
Becoming a Backend Developer WEEK EIGHT Backend Development: RESTful APIs WEEK EIGHT Table of contents 01 is a RESTful What 02 Project Folder API?...
Becoming a Backend Developer WEEK EIGHT Backend Development: RESTful APIs WEEK EIGHT Table of contents 01 is a RESTful What 02 Project Folder API? Structuring Introduction to RESTful APIs Importance, Example Disclaimer: This training material belongs to TechCrush and 3 01 What is a RESTful API? Introduction to RESTful APIs Disclaimer: This training material belongs to TechCrush and 4 What is a RESTful API? A RESTful API (Representational State Transfer API) is an architectural style for designing networked applications. It focuses on a stateless, client-server communication protocol, typically using HTTP and communicates using JSON (or XML). Resources are identified by URLs and manipulated using the following operations: GET: Retrieve a resource. POST: Create a new resource. PUT/PATCH: Update an existing resource. DELETE: Remove a resource. The REST setup stateless interactions, meaning each request from a client contains all the information needed to process it, without relying on stored context on the server side Disclaimer: This training material belongs to TechCrush and 5 Key aspects of RESTful APIs Stateless: The server does not store any client state between requests. Each request contains all the information needed to process it. Every request is treated as independent. Resource-Oriented: REST APIs operate on resources (like users, posts, products). Resources are represented by URLs (e.g., /users, /products/1). Uniform Interface: The API uses a consistent and predictable structure for all endpoints, following HTTP standards. Layered System: The API is designed in layers, allowing separation of concerns (e.g., business logic, database, and client layers). This allows for load balancing, shared caches, security layers. Client cannot tell whether it's connected directly to the end server. Cacheable: Responses should be explicitly marked as cacheable or non-cacheable to improve performance (and reduce server load). Disclaimer: This training material belongs to TechCrush and 6 RESTful API Design Criteria Use HTTP Methods Properly Use Status Codes GET: Retrieve data. 200 OK: Request successful. POST: Create new data. 201 Created: New resource created. PUT or PATCH: Update existing data. 400 Bad Request: Client sent invalid data. DELETE: Remove data. 401 Unauthorized: Missing or invalid authentication. 404 Not Found: Resource not found. Proper and Uniform Resource 500 Internal Server Error: Server-side Naming issue. Use nouns for resources (e.g., /users, /orders), not verbs (e.g., /getUsers). Use plural names for collections (e.g., Statelessness /products, /users). Do not store client-specific data on the server GET /users # List users between requests. GET /users/123 # Get specific user Include authentication tokens (e.g., JWT) in POST /users # Create user headers for each request. PUT /users/123 # Update entire user Disclaimer: This training material belongs to TechCrush and 7 RESTful API Design Criteria Provide Pagination Consistent Error Handling For large datasets, include pagination (e.g., { /users?page=1&limit=20). "error": true, "message": "Resource not found", Versioning "status": 404 Use API versioning to prevent breaking } changes (e.g., /api/v1/users). Documentation Create API documentation (e.g., Swagger or Postman collections) to help developers understand your API. Disclaimer: This training material belongs to TechCrush and 8 02 Project Folder Structuring Importance, Example Disclaimer: This training material belongs to TechCrush and 9 Project Folder Structuring A well-organized folder structure is crucial in software development and file management, positively impacting productivity, collaboration, and project maintenance. 1. Navigability and Readability: A clear folder structure enhances the readability of a codebase, making it easier for developers to navigate. 2. Collaboration and Onboarding: In team environments, a well-defined folder structure speeds up the onboarding process for new developers. It reduces conflicts when multiple team members work on different parts of the project simultaneously. 3. Maintenance and Debugging: When issues arise in a project, an organized folder structure allows developers to isolate problems more quickly. This organization can significantly reduce debugging time and improve overall maintenance efficiency. 4. Minimal Risk of Data Loss or Misplacement: A structured approach minimizes the chances of data loss or misplacement by ensuring that every file has its designated place. This organization not only protects against accidental deletions but also facilitates better backups. Disclaimer: This training material belongs to TechCrush and 10 A Typical Node.js Project Folder Structure Disclaimer: This training material belongs to TechCrush and 11 A Typical Node.js Project Folder Structure src (Source Code): The main directory containing all application code config: Configuration files for database, environment variables, etc. controllers: Handle request and response logic models: Database schema and data models routes: Define API endpoint routes services: Business logic and database interactions middlewares: Custom Express middlewares utils: Utility functions and helper classes helpers: Specific helper functions for complex operations types: TypeScript type definitions or prop type validations app.js: Main application entry point tests Organized into unit, integration, and end-to-end tests Mirrors the structure of the src directory docs Documentation for API specifications Database schema documentation logs: Storing application logs scripts: Utility scripts for database seeding, migrations, etc. Disclaimer: This training material belongs to TechCrush and 12 Thank You! Disclaimer: This training material belongs to TechCrush and 13