Giter Site home page Giter Site logo

onlinecourseapi's Introduction

Online Coure-API

This is a Ruby on Rails API from which the React frontend serves the data. It is a simple Rails app that has three models - User, Course and Favourite. For the authentication of the users I used JSON Web Tokens. The API is hosted on Heroku, at this endpoint: career-coaches-api - But they can only be accessed with a valid API token. The front end can be found here

Built With

  • Ruby v2.7.0
  • Ruby on Rails 6.0.3.4
  • Rspec
  • JWT

API Documentation

The base URL for all the endpoints is https://desolate-cove-81044.herokuapp.com/. All request sent to any of the end-points excepts /users and /login are first validated. The validation is done using tokens generated by JWT upon registration or login. These token has to be sent in the headers of the request you are making in order to successfully access those end-points.

Register

This API endpoint is used for registering new users to the system and doesn't require authorization.

Endpoint

https://desolate-cove-81044.herokuapp.com/users

Sample Request

curl -X GET \
 https://desolate-cove-81044.herokuapp.com/users \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d 'username=user&password=asdfgh'

Sample Response

[
    {
        "id": 31,
        "first_name": "Muhammad",
        "last_name": "Umer",
        "username": "ator",
        "user_type": "author",
        "email": "[email protected]"
    },
    {
        "id": 33,
        "first_name": "Muhammad",
        "last_name": "Umer",
        "username": "user1",
        "user_type": "user",
        "email": "[email protected]"
    }
]

Login

This API endpoint is used for logging in a user into the system and also does not require authorization, just the username and password that was used in creating an account and that will be added to the request body.

Endpoint

https://desolate-cove-81044.herokuapp.com/login

Sample Request

curl -X POST \
  https://desolate-cove-81044.herokuapp.com/login \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d 'username=user&password=asdfgh'

Sample Response

{
{
    "user": {
        "id": 30,
        "first_name": "Muhammad",
        "last_name": "Umer",
        "username": "user",
        "user_type": "user",
        "email": "[email protected]"
    },
    "token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjozMH0.SFhd9-6MMh5MyurW1vcuigvooMDIxElIJIZLBB2nOf4"
}

Get Courses

This API endpoint return all the Courses.

Endpoint

https://desolate-cove-81044.herokuapp.com/courses/

Sample Request

curl -X GET \
 https://desolate-cove-81044.herokuapp.com/courses \
  -H 'Authorization: Bearer <Token>' \
  -H 'cache-control: no-cache' \

Sample Response

[
    {
        "course_id": 82,
        "title": "React and Redux",
        "details": "Avery nice course",
        "author": 32,
        "requirements": "No Requirements",
        "difficulty": "Beginners",
        "image": "https://www.wrappixel.com/wp-content/uploads/2019/08/guide-for-react-redux.jpg",
        "price": "150",
        "date": "2021-03-05T01:41:36.194Z"
    }
]

Add New Course

This is the API endpoint related to adding course.

Endpoint

https://desolate-cove-81044.herokuapp.com/courses/

Sample Request

curl -X POST \
  https://desolate-cove-81044.herokuapp.com/courses/ \
  -H 'Authorization: Bearer <Token>' \
  -H 'cache-control: no-cache' \
  -d 'title=title&details=details&author=author&requirements=requirements&difficulty=difficulty&image=image&price=price'

Sample Response

  • If the appointment was created:
{
    "course_id": 82,
    "title": "React and Redux",
    "details": "Avery nice course",
    "author": 32,
    "requirements": "No Requirements",
    "difficulty": "Beginners",
    "image": "https://www.wrappixel.com/wp-content/uploads/2019/08/guide-for-react-redux.jpg",
    "price": "150",
    "date": "2021-03-05T01:41:36.194Z"
}
  • if there was an error:
{
  "error": "400 bad request"
}

Add to Favourites

This is the API endpoint related to adding course to user favourites.

Endpoint

https://desolate-cove-81044.herokuapp.com/courses/:id

Sample Request

curl -X POST \
  https://desolate-cove-81044.herokuapp.com/favourites/ \
  -H 'Authorization: Bearer <Token>' \
  -H 'cache-control: no-cache' \
  -d 'user_id=2&course_id:2'

Sample Response

{
    "course_id": 2,
    "title": "Gulistan E Saadi",
    "details": "A very Nice Course",
    "author": 2,
    "requirements": "No Requirements",
    "difficulty": "Intermediate",
    "image": "https://www.wrappixel.com/wp-content/uploads/2019/08/guide-for-react-redux.jpg",
    "price": "50",
    "date": "2021-03-05T04:44:42.928Z"
}
  • if empty:

[]

Remove From Favourites

This is the API endpoint related to removing course from user favourites.

Endpoint

https://desolate-cove-81044.herokuapp.com/courses/:id

Sample Request

curl -X POST \
  https://desolate-cove-81044.herokuapp.com/favourites/ \
  -H 'Authorization: Bearer <Token>' \
  -H 'cache-control: no-cache' \
  -d 'user_id=30&course_id:82'

Sample Response

{
   Removed From Favourites
}

Getting Started

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

Prerequisites

Ruby: 2.7.0 Rails: 6.0.3.4 Postgres: >=9.5

Setup

Install gems with:

bundle install

Setup database with:

   rails db:create
   rails db:migrate

Usage

Start server with:

    rails server
  • You can then proceed to test the different end point via postman or any choice of yours.

Run tests

Type the following in your terminal/command line to run tests for the API:

    rpsec

Deployment

This API has been deployed on heroku. It is acccessible at https://desolate-cove-81044.herokuapp.com/.

Author

Reach out to me!

Muhammad Fahad Umer

Contributing ๐Ÿค

Contributions, issues, and feature requests are welcome!

Feel free to check the issues page.

Acknowledgments

  • Thanks to Microverse for its support!
  • Thanks React Community
  • Thanks to Marc-Antoine Roy for his awesome Designs.
  • Thanks to behance

Show your support

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

License

License

onlinecourseapi's People

Contributors

mfahadumer avatar

Watchers

 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.