Giter Site home page Giter Site logo

oxenprogrammer / developer-wear Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 75 KB

Ruby on Rails REST API endpoint with JWT Authentication and Authorization with post and get request.

Ruby 99.53% HTML 0.47%
ruby ruby-on-rails jwt rspec rest-api backend

developer-wear's Introduction

Sudo Wear

Sudo Wear is a Rails 6 API tied to a frontend written in react, made using the methodology and indications of the Capstone Project provided by Microverse. It provides endpoints to consume with an front-end client.

The documentation of this API is still under developement, I have manually documented the available endpoints below.

Nice to Have I chose to implement a proper authentication since security is very important when collecting real user imformation. Users are protected by the Data Protection Policy updated in 2019

Built With

  • Ruby v3.01
  • Ruby on Rails v6.1.0
  • Rspec
  • JWT
  • heroku
  • Cloudinary
  • Carrierwave

The Web App

The client live version of this project is on Sudo Wear

Getting Started

To get a local copy up and running follow these simple example steps.Δ°nitial

Setup

  • Clone this repository with git clone https://github.com/oxenprogrammer/developer-wear.git using your terminal or command line.
  • Create a cloudinary account since all images are stored in the cloud. Check Cloudinary for details on how to create an account.
  • Change to the project directory by entering cd developer-wear in the terminal
  • Create a .env file in the root directory and use .env_example to put the right environment variables.
  • Next run bundle install to install the necessary dependencies
  • Run rails db:migrate to setup your local database.
  • Run rails db:create in case the migration doesn't run the first time.
  • Run rails db:seed to get seeded data for project. You will need to

Usage

Start server with:

    rails server

Open http://localhost:3000/ in your browser.

Run tests

for test formatting add below script in .rspec file

    rpsec --format documentation

To run all the tests run below script in the terminal

rspec

Sudo Wear API endpoints

BASE_URL = server/api/v1/

Register User

Route: BASE_URL/users POST Request

  {
    "email": "[email protected]",
    "username": "john",
    "password": "123456",
    "password_confirmation": "123456"
  }

Success Response Body

  {
    "id": 7,
    "username": "ojok123444",
    "email": "[email protected]",
    "password_digest": "$2a$12$GNp45y5xQKEskyzCEq1i..oqC.6IXsL9rYVt2riw.aELLAgMuFPRe",
    "admin": false,
    "created_at": "2021-08-08T14:38:46.279Z",
    "updated_at": "2021-08-08T14:38:46.279Z"
  }

Login User

Route: BASE_URL/login POST Request

  {
    "email": "[email protected]",
    "password": "123456"
  } 

Success Response Body

  {
    "token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo3fQ.B4o3uuM9PffSX50Dv-Idupe9jAfw4AQYXINCXBOLicA",
    "email": "[email protected]",
    "username": "ojok123444",
    "admin": false
  }

Get Shirts

Route: BASE_URL/shirts Header: Authorization: "Bearer Token" GET Request

Success Response Body

  {
    "status": "ok",
    "count": 1,
    "data": [
        {
            "id": 4,
            "name": "no coffee no code",
            "description": "developers need coffee in order to execute their task successfully",
            "image": {
                "url": "http://res.cloudinary.com/emmisteel/image/upload/v1627507461/sl1xydorburv4rpcceie.jpg"
            },
            "price": 32000,
            "created_at": "2021-07-27T09:50:36.615Z",
            "updated_at": "2021-07-27T11:22:53.996Z"
        },
    ]
  }

Get Favourite Shirts

Route: BASE_URL/favourites Header: Authorization: "Bearer Token" GET Request

Success Response Body

  {
    "status": "ok",
    "count": 1,
    "data": [
        {
            "id": 4,
            "name": "no coffee no code",
            "description": "developers need coffee in order to execute their task successfully",
            "image": {
                "url": "http://res.cloudinary.com/emmisteel/image/upload/v1627507461/sl1xydorburv4rpcceie.jpg"
            },
            "price": 32000,
            "created_at": "2021-07-27T09:50:36.615Z",
            "updated_at": "2021-07-27T11:22:53.996Z"
        },
    ]
  }

Get Single Shirts

Route: BASE_URL/shirts/:id Header: Authorization: "Bearer Token" GET Request

Success Response Body

  {
    
    "id": 4,
    "name": "no coffee no code",
    "description": "developers need coffee in order to execute their task successfully",
    "image": {
        "url": "http://res.cloudinary.com/emmisteel/image/upload/v1627507461/sl1xydorburv4rpcceie.jpg"
    },
    "price": 32000,
    "created_at": "2021-07-27T09:50:36.615Z",
    "updated_at": "2021-07-27T11:22:53.996Z"
      
  }

Get Shirts

Route: BASE_URL/shirts Header: Authorization: "Bearer Token" GET Request

Success Response Body

  {
    "status": "ok",
    "count": 1,
    "data": [
        {
            "id": 4,
            "name": "no coffee no code",
            "description": "developers need coffee in order to execute their task successfully",
            "image": {
                "url": "http://res.cloudinary.com/emmisteel/image/upload/v1627507461/sl1xydorburv4rpcceie.jpg"
            },
            "price": 32000,
            "created_at": "2021-07-27T09:50:36.615Z",
            "updated_at": "2021-07-27T11:22:53.996Z"
        },
    ]
  }

Get All Users

Route: BASE_URL/users Header: Authorization: "Bearer Token" GET Request

Success Response Body

  {
    "status": "ok",
    "count": 2,
    "data": [
        {
            "id": 2,
            "username": "moses",
            "email": "[email protected]"
        },
        {
            "id": 1,
            "username": "emmysteel",
            "email": "[email protected]"
        },
    ]
  }

Add Shirt

Route: BASE_URL/shirts Header: Authorization: "Bearer Token" POST Request (Form Data)

    "name": "[email protected]",
    "description": "123456",
    "price": 3000,
    "image": Base64 Image

Success Response Body

  {
    "id": 9,
    "name": "CMD",
    "description": "As a programmer, you will spend a lot of time at the command line. love it, embrace it.",
    "image": {
        "url": null
    },
    "price": 40000,
    "created_at": "2021-08-08T15:00:39.763Z",
    "updated_at": "2021-08-08T15:00:39.763Z"
  }

Author

πŸ‘€ Emanuel Okello

🀝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check the issues page.

Acknowledgments

  • Several YouTube Videos
  • Several Medium Articles
  • Microverse

Show your support

Give a ⭐️ if you like this project!

πŸ“ License

This project is MIT licensed.

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.