An API for an animal shelter, giving info about name, species, age, breed and sex. I also created a React front end for this project which can be found here
- Ruby
- Gems
- Bundler
- RSpec
- Shoulda Matchers
- IRB
- Pry
- Postgres
- SQL
- Rails
- ActiveRecord
- Faker
- Will Paginate
- Factory Bot
- Rack-cors
This project was created to show proficiency in Rails with Active Record for creating APIs. The application is for an API that allows users to retrieve information about animals in a shelter including name, species, age, breed and sex. The user can add/remove/edit animals in the database.
- The user can get all animals with a standard get call or if they'd like can add a page parameter to get paginated results (used will_paginate gem for this).
- The user can search for a random animal by adding /random to the end of a normal /animals get call, this was made with a custom route in the controller.
- The user can search by breed, species or sex individually, or also species and sex combined, these were achieved with custom scopes and these searches are case insensitive. All routes mentioned here detailed in the graph below.
- This API has CORS enabled for all origins and all resources (rack-cors gem enabled for this).
- This API uses namespacing of the controller to create versioning.
- Ruby v2.6.5 recommended
- Postgres 12.9
(Note: Ruby gem dependencies will be installed automatically by Bundler.)
- Clone the GitHub repository: https://github.com/Frank-Proulx/w13_animal_shelter
- From the main project directory, enter
bundle install
in the terminal to populate gems. - To create a database, type in your terminal:
rake db:setup
- Enter
rspec
into the terminal to confirm passing of all tests. - Run
rails s
to start the Rails server. - Use an api platform (such as Postman) or integrate into a front end application using the routes listed below.
Usage | METHOD | URL | Params |
---|---|---|---|
See Animals | GET | http://localhost:3000/api/v1/animals |
|
See Animals (Paginated) | GET | http://localhost:3000/api/v1/animals?page=param |
page |
See A Specific Animal | GET | http://localhost:3000/api/v1/animals/:id |
|
Search By Animal Breed | GET | http://localhost:3000/api/v1/animals?breed=param |
breed |
Search By Animal Species | GET | http://localhost:3000/api/v1/animals?species=param |
species |
Search By Animal Sex | GET | http://localhost:3000/api/v1/animals?sex=param |
sex |
Search By Animal Species & Sex | GET | http://localhost:3000/api/v1/animals?species=param&sex=param |
species, sex |
See A Random Animal | GET | http://localhost:3000/api/v1/animals/random |
|
Create An Animal | POST | http://localhost:3000/api/v1/animals?name=param&species=param&age=param&breed=param&sex=param |
name, species, age, breed, sex |
Update An Animal (any or all parameters) | PUT | http://localhost:3000/api/v1/animals/:id?name=param&species=param&age=param&breed=param&sex=param |
name, species, age, breed, sex |
Delete An Animal | DELETE | http://localhost:3000/api/v1/animals/:id |
|
*for endpoints with params, replace any param
in the sample routes with your chosen param(s).
A response for a single animal will have the following format:
{
"id" : integer,
"name" : string,
"species" : string
"age" : integer
"breed" : string
"sex" : string
}
No known bugs at this time.
If you have any issues, questions, ideas or concerns, please reach out to me at my email and/or make a contribution to the code via GitHub.
Copyright (c) 2022 Frank Proulx