This is a REST API that calls an external API service to get information about books and also perform simple CRUD(Create, Read, Update, Delete) operations on it.
To get started with the API, follow these instructions:
You need to have the following installed on your system:
- Ruby (version 3.0 or higher)
- Rails (version 7.0.6 )
- Clone the repository:
git clone https://github.com/G-vans/book-api-rails.git
cd book-api-rails
- Install the required gems:
bundle install
- Create and migrate the database then start the server:
rails db:create
rails db:migrate
rails s
Now the API should be up and running at 'http://localhost:3000'.
The following are the available API endpoints:
- Endpoint: GET /external_books
- Params: name (string, required)
- Response: Returns a list of external books matching the given name.
- Endpoint: POST /books
- Params:
- name (string, required)
- isbn (string, required)
- authors (array of strings, required)
- number_of_pages (integer, required)
- publisher (string)
- country (string)
- release_date (string in the format "YYYY-MM-DD")
- Response: Returns the details of the newly created book.
- Endpoint: GET /books
- Response: Returns a list of all books in the bookstore.
- Endpoint: GET /books/:id
- Params: id (integer, required)
- Response: Returns the details of the specified book.
- Endpoint: PATCH /books/:id
- Params: Same as create endpoint
- Response: Returns the updated details of the book.
- Endpoint: DELETE /books/:id
- Params: id (integer, required)
- Response: Returns a success message if the book was deleted successfully.
The API returns appropriate error responses with status codes and error messages in case of any issues with the requests.
To run the test suite and verify that the API endpoints are functioning as expected, use the following command:
bundle exec rspec
Contributions are welcome! If you find any issues or want to add new features, feel free to create a pull request.