Skip to content

AhsanSheraz/Ruby-Blog

Repository files navigation

Restful API's for Blogging in ROR

This is the Ruby web based application, have Restful API's for a Blog application.

  • Pre-Req: You should have docker & docker-compose install on your machine.

Steps to run the application:

  • Clone the project by "git clone repo-url"

  • Open project directory into terminal.

  • Type "docker-compose up --build"

  • After building and running all the container open pgadmin for DB configuration.

  • First create a server from the panel on the left side as shown below:

    • step 1:
      Screenshot (46)
    • step 2:
      Screenshot (43)
    • step 3 : At this step just click on save, after adding the configuration.
      Screenshot (45)
  • Now create a DB with the name of "blog_app_production" as shown below:

    • step 1: Screenshot (47)
    • step 2: At this step just click on save, after adding the DB name. Screenshot (48)
  • Now hit the Open App, your application is up and running.

  • Now open another terminal, run the below commands:

    • Run command "docker exec -it blog-app bash" to access docker container terminal.
    • Type command on docker container terminal "rake db:migrate" for db migrations.
    • At the end, type command "rake db:seed" to generate dummy data.
  • Default login users:

    • Email: user[1 to 100]@example.com
    • Password for all users: password

API's covered in this app:

  • Note: You need to set Authentication token in against each API (except login), to communicate the server.

    • Set authorization in headers as shown below:
      Screenshot (49)
  • Login API: (POST request)

    • Description: This API will be used for login and get token against a user.
    • URL: http://localhost:3000/login
    • Payload: { "email": "user1@example.com", "password": "password" }
    • Response: { "token": "1ab103011d3672342821145e3762d949" }
  • Creat Post API: (POST request)

    • Description: This API will craete a post against a user.
    • URL: http://localhost:3000/posts
    • Payload: { "title": "Post Number postman", "context": "This post is agains", "user_ip": "192.168.1.100" }
    • Response: { "post": { "id": 6515, "title": "Post Number postman", "context": "This post is agains", "created_at": "2021-10-09T16:03:55.469Z" } }
  • Rate a Post API: (POST request)

    • Description: This API will be used to rate a Post (Rating will be between 1 to 5). And it will return the average of all the ratings against that Post.
    • URL: http://localhost:3000/ratings
    • Payload: { "rate": 5, "post_id": 20 }
    • Response: { "average_rating": 4.8, "post_id": 20 }
  • Get top N post by average rating: (GET request)

    • Description: This API will be used to get top N number of posts by average rating, by default value of showPosts is 5.
    • URL: http://localhost:3000/top/posts?showPosts=1
    • Response: { "message": [ { "title": "Post Number 1528", "context": "This post is against user 1" } ] }
  • Get IP's & authors, against the IP of Post: (GET request)

  • Get All Post: (GET request)

    • Description: This API will return all the Posts. Pagination is also implement in this API, default it wil return 1 page with 5 values.
    • URL: http://localhost:3000/posts?page=1&per_page=2
    • Response: { "posts": [ { "id": 6516, "title": "Post Number 1", "context": "This post is against user 1", "created_at": "2021-10-10T09:52:35.639Z" }, { "id": 6517, "title": "Post Number 2", "context": "This post is against user 1", "created_at": "2021-10-10T09:52:35.659Z" } ] }
  • Get All Users: (GET request)

  • Get All Ratings: (GET request)

    • Description: This API will return all the Rating against every Post.
    • URL: http://localhost:3000/ratings
    • Response: { "ratings": [ { "id": 3479 }, { "id": 3480 } ] }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages