This is a simple Blog API developed using Ruby on Rails, implementing RESTful principles. It's designed to allow interaction with a PostgreSQL database to create, read, update, and delete blog posts. Each post contains a title, a body, and a read count with the average time a reader would take.
This is backend behaves the same as the Java Spring Blog Api, just wanted to create the same on a different technology stack.
- Ruby 3
- Ruby on Rails 7
- PostgreSQL
- RSpec for Testing
- Ruby 3
- Ruby on Rails 7
- PostgreSQL
-
Clone the repository to your local machine.
git clone https://github.com/alexertech/blog_api.git cd blog_api
-
Install the required gems.
bundle install
-
Setup the database.
rails db:create rails db:migrate
-
Run the server.
rails server
-
The application will be available at
http://localhost:3000
.
To run the test suite, execute the following command in the project directory:
rspec
curl -X GET http://localhost:3000/posts
curl -X POST -H "Content-Type: application/json" -d '{"title": "Sample Post", "body": "This is a sample post."}' http://localhost:3000/posts
curl -X PUT -H "Content-Type: application/json" -d '{"title": "Updated Title", "body": "Updated Body"}' http://localhost:3000/posts/1
curl -X DELETE http://localhost:3000/posts/1
curl -X GET http://localhost:3000/posts/1
curl -X GET http://localhost:3000/posts/1/read_time