Houzia API a RESTful API that allows authenticated user to add and manipulate houses available for rent. This is a final capstone project as part of Microverse's Technical curriculum. The project details can be found here. The goal of the project is to build an API that is consumed by a React App.
- Ruby v2.7.0
- Ruby on Rails v6.0.3.2
- Ruby
- Ruby On Rails
- Ruby: 2.7.0
- Rails: 6.0.2.1
Use the git to clone the project to your local machine.
$ git clone https://github.com/OlukaDenis/houzia-api.git
Navigate to the extracted folder
$ cd houzia-api
Install the gems
$ bundle install
Create the database
$ rails db:create
Run the migrations
$ rails db:migrate
Create admin user with:
$ rails db:seed
Start server with:
$ rails s -p 4000
Open http://localhost:4000/
in your browser.
Login as admin user:
email: [email protected]
password: 15qwerty
Or create a normal user without admin rights using /signup
endpoint.
$ bundle exec rpsec --format documentation
Returns an authentication token to authorize the subsequent resquests.
-
URL:/signup
-
Method:
POST
-
URL Params: None
-
Body Params Required:
username=[string]
email=[string]
image=[string
password=[string]
password_confirmation=[string]
-
Success Response:
- Code: 201
- Status: Created
- Response body:
{ message: "Account created successfully", auth_token: "JWT_GENERATED_TOKEN" }
-
Error Response:
- Code: 422
- Status: Unprocessable Entity
- Response body:
{ message: "Missing any of the required fields" }
-
Sample Call:
axios.post(`${BASE_URL}/signup`, { username: 'John Doe', email: '[email protected]', image: 'https://img.com/image.png', password: '123456', password_confirmation: '123456', }) .then(response => console.log(response)) .catch(error => console.log(error))
Returns an authentication token to authorize an existing user.
-
URL /auth/login
-
Method:
POST
-
URL Params None
-
Body Params Required:
email=[string]
password=[string]
-
Success Response:
- Code: 200
- Status: OK
- Response body:
{ auth_token: "JWT_GENERATED_TOKEN" }
-
Error Response:
- Code: 401
- Status: Unauthorized
Response body:
{ message: "Invalid Credentials" }
-
Sample Call:
axios.post(`${BASE_URL}/auth/login`, { email: "[email protected]", password: "123456", } ) .then(response => console.log(response)) .catch(error => console.log(error))
Returns a list of all available houses.
-
URL:/houses
-
Method:
GET
-
URL Params: None
-
Authorization: Bearer Token
-
Body Params Required: None
-
Success Response:
- Code: 200
- Status: OK
- Response body:
[ { id: 1, name: "House for rent", description: "Description info", image: "image.png", price: 50000, user_id: 1, created_at: "2020-09-03T16:30:41.855Z", updated_at: "2020-09-03T16:30:41.855Z" } ]
-
Error Response:
- Code: 422
- Status: Unprocessable Entity
- Response body:
{ message: "Missing token" }
-
Sample Call:
axios.get(`${BASE_URL}/houses`, { headers: { Authorization: "Bearer Token", }, }) .then(response => console.log(response)) .catch(error => console.log(error))
Returns a json data of the created house
-
URL:/houses
-
Method:
POST
-
URL Params: None
-
Authorization: Bearer Token
-
Body Params Required:
name=[string]
description=[text]
image=[string]
price=[integer]
-
Success Response:
- Code: 201
- Status: Created
- Response body:
{ id: 1, name: "House for rent", description: "Description info", image: "image.png", price: 50000, user_id: 1, created_at: "2020-09-03T16:30:41.855Z", updated_at: "2020-09-03T16:30:41.855Z" }
-
Error Response:
- Code: 422
- Status: Unprocessable Entity
- Response body:
{ message: "Missing token" }
-
Sample Call:
axios.post(`${BASE_URL}/houses`, { name: "House for rent", description: "Description info", image: "image.png", price: 50000 }, { headers: { Authorization: "Bearer Token", }, }) .then(response => console.log(response)) .catch(error => console.log(error))
๐ค Denis Oluka
Contributions, issues and feature requests are welcome!
Give a โญ๏ธ if you like this project!
This project is licensed under MIT license - see LICENSE for more details.