Coder Social home page Coder Social logo

houzia-api's Introduction

Project: Houzia API

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.

Built With

  • Ruby v2.7.0
  • Ruby on Rails v6.0.3.2

Technologies

  • Ruby
  • Ruby On Rails

Live Demo

Live link

Prerequisites

  • Ruby: 2.7.0
  • Rails: 6.0.2.1

Setup

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

Usage

Admin User

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.

Run tests

    $ bundle exec rpsec --format documentation

API Documentation

Signup User

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))

Login User

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))

Get all houses

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))

Admin Endpoints

Add new house

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))

Author

๐Ÿ‘ค Denis Oluka

Github | Twitter | LinkedIn

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!

Show your support

Give a โญ๏ธ if you like this project!

๐Ÿ“ License

This project is licensed under MIT license - see LICENSE for more details.

houzia-api's People

Contributors

olukadenis avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.