A simple API built with Ruby on Rails to demonstrate basic CRUD operations. This project showcases my current knowledge in creating RESTful APIs with Ruby on Rails, including setting up routes, controllers, and models, as well as handling JSON responses and app testing.
This project is designed to provide a basic understanding of how to create a RESTful API using Ruby on Rails. It includes endpoints for creating, reading, updating, and deleting resources.
- RESTful API endpoints for CRUD operations
- JSON responses
- Basic authentication (JWT) and authorization
- Error handling and validation
- Testing
Follow these instructions to set up the project on your local machine.
- Ruby (version 3.3.3)
- Rails (version 7.1.3)
- MySQL (or another preferred database)
- Clone the repository:
git clone https://github.com/uoshvis/vixted_api.git
- Navigate to the project directory:
cd vixted_api - Install dependencies:
bundle install
- Export MySQL password:
export DB_PASS="your_password"
- Install dependencies:
rails db:create db:migrate
rails server
rails test
| Prefix | Verb | URI Pattern | Controller#Action |
|---|---|---|---|
| api_v1_user_items | GET | /api/v1/users/:user_id/items(.:format) | api/v1/items#index |
| api_v1_user_item | GET | /api/v1/users/:user_id/items/:id(.:format) | api/v1/items#show |
| api_v1_users | GET | /api/v1/users(.:format) | api/v1/users#index |
| api_v1_users | POST | /api/v1/users(.:format) | api/v1/users#create |
| api_v1_user | GET | /api/v1/users/:id(.:format) | api/v1/users#show |
| api_v1_user | DELETE | /api/v1/users/:id(.:format) | api/v1/users#destroy |
| search_api_v1_items | GET | /api/v1/items/search(.:format) | api/v1/items#search |
| api_v1_items | GET | /api/v1/items(.:format) | api/v1/items#index |
| api_v1_items | POST | /api/v1/items(.:format) | api/v1/items#create |
| api_v1_item | GET | /api/v1/items/:id(.:format) | api/v1/items#show |
| api_v1_item | PATCH | /api/v1/items/:id(.:format) | api/v1/items#update |
| api_v1_item | PUT | /api/v1/items/:id(.:format) | api/v1/items#update |
| api_v1_item | DELETE | /api/v1/items/:id(.:format) | api/v1/items#destroy |
| api_v1_me | GET | /api/v1/me(.:format) | api/v1/users#me |
| api_v1_auth_login | POST | /api/v1/auth/login(.:format) | api/v1/auth#login |
https://vixted-api.onrender.com/api/v1/items
To use live version:
- Create user.
- Get token.
- Use token for CRUD.
Request
POST /api/v1/items HTTP/1.1
Host: example.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json
{
"title": "Sample Item",
"description": "This is a sample description.",
"price": 19.99,
}
Response
HTTP/1.1 201 Created
Content-Type: application/json
Location: /api/v1/items/1
{
"id": 1,
"title": "Sample Item",
"description": "This is a sample description.",
"price": 19.99,
"user": {
"id": 1,
"username": "user1"
}
}
- Ruby on Rails
- MySQL
- Postman (for API testing)
- factory_bot (for testing)
This project is licensed under the MIT License - see the LICENSE file for details.
GitHub: uoshvis