Giter Club home page Giter Club logo

blog-app-api-practice's Introduction

blog-app-api-practice

Blog app: add API endpoints project where, as the name indicates, I had to add API endpoints to the already created project in the Social Media website. The endpoints created are for the following actions:

  • List all posts for a user.
  • List all comments for a user's post.
  • Add a comment to a post.
  • Implement authentication

Since the original project, authentication was implemented with the devise gem. For the API project authentication was implemented with the jwt gem in a separate way, such that both the original project with the frontend in .erb views and also the API project with the particular endpoints requested lived together. All the API endpoints controller are located in it's respective API namespace folder inside the controller's directory.

All the endpoints for the API project has it's respective tests with RSpec since their development was following TDD.

Built With

  • Ruby 2.7.6
  • Rails 6.0.3.4

Getting Started

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

Setup

If not using ruby version 2.7.6, please install with rvm

  rvm install ruby-2.7.6

After installing the ruby version, run the command to use that version of ruby

  rvm use ruby-2.7.0

Install gems with:

bundle install

Install node packages with yarn

yarn install

Setup database with:

   rails db:create
   rails db:migrate

Usage the Web App

To start the server and use it on the browser, run:

    rails server

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

Usage the API

You can test the API endpoints with an app that sends HTTP Requests such as Postman. Have the app running with

  rails s

The API endpoints are:

For all the Posts of a particular User

GET localhost:3000/api/users/:user_id/posts

For all the Comments on a particular Post for a User

  GET localhost:3000/api/users/:user_id/posts/:post_id/comments

For adding a Comment on a particular Post for a User

  POST localhost:3000/api/users/:user_id/posts/:post_id/comments

Swagger tests

To see the swagger documentation, once the app is running with rails s, go to the following URL:

  http://localhost:3000/api-docs/index.html

Run tests

Download and install google chrome if don't have it to run Capybara. Capybara needs the web drivers to run system tests with browsers

  wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
	
  rspec --format documentation

To run the tests of just the API endpoints, run

rspec spec/controllers

Author

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check the issues page.

Show your support

Give a ⭐️ if you like this project!

Acknowledgments

A special thanks to the Ruby Team.

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.