Week 13 Building an API Part 1 - Code-the-Dream-School/rails-guidebook GitHub Wiki
Week | Topic | Learning Objectives | Key Resources |
---|---|---|---|
13 | Building an API Part 1 |
|
Lesson Materials Coding Assignment |
-
Introduction to REST and JSON
- Understand RESTful principles and HTTP methods (GET, POST, PUT, PATCH, DELETE).
- Learn how JSON is used for request and response bodies.
-
Authentication and Authorization
- Implement user registration and authentication using Devise.
- Learn about HTTP-only cookies for storing authentication tokens and security considerations.
-
CRUD Operations
- Create and manage CRUD operations for
Member
andFact
models. - Implement access control to ensure users can only access their own data.
- Create and manage CRUD operations for
-
Testing and Documentation
- Use Postman to test REST APIs.
- Document APIs using Swagger and Rspec test cases.
-
Error Handling
- Implement error handling for invalid requests and exceptions.
-
Security Considerations
- Address CSRF protection and proper handling of security tokens.
-
Initial Setup
- Fork and clone the starter Rails repository.
- Create a
lesson12
branch. - Add necessary gems:
devise
,email_validator
,strong_password
. - Configure Rails session and Devise.
-
Creating Controllers
- Generate
users/Registrations
,users/Sessions
, andtest
controllers. - Implement JSON response handling in
RegistrationsController
andSessionsController
. - Create
AuthenticationCheck
concern and integrate it into controllers. - Configure routes for user registration, session management, and testing.
- Generate
-
Testing with Postman
- Create and test GET, POST, and DELETE requests in Postman.
- Verify user registration, login, and logout functionality.
-
Models and Associations
- Generate
Member
andFact
models. - Implement model validations and associations.
- Migrate databases.
- Generate
-
Controllers and Routes for CRUD Operations
- Generate API controllers for
Members
andFacts
. - Implement CRUD operations and access control in controllers.
- Set up routes with namespaces for API versioning.
- Generate API controllers for
-
Exception Handling
- Create
ExceptionHandler
module and include it inApplicationController
.
- Create
-
CSRF Protection
- Implement CSRF token handling and set
skip_forgery_protection
where necessary. - Configure Postman environment to handle CSRF tokens.
- Implement CSRF token handling and set
-
Submission
- Commit changes and push to GitHub.
- Open a pull request for review.
Ensure each of these tasks is completed to fully implement the API and prepare it for testing and submission.