Skip to content

An API for a fictitious animal shelter. This API has full crud functionality, as well as custom endpoints, scopes for searching by different parameters, pagination, CORS, versioning and more.

Notifications You must be signed in to change notification settings

Frank-Proulx/w13_animal_shelter

Repository files navigation

Animal Shelter API

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

Created By: Frank Proulx

Technologies Used

  • Ruby
  • Gems
  • Bundler
  • RSpec
  • Shoulda Matchers
  • IRB
  • Pry
  • Postgres
  • SQL
  • Rails
  • ActiveRecord
  • Faker
  • Will Paginate
  • Factory Bot
  • Rack-cors

Description

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.

Further Exploration Objectives

  • 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.

System Requirements

  • Ruby v2.6.5 recommended
  • Postgres 12.9
    (Note: Ruby gem dependencies will be installed automatically by Bundler.)

Setup/Installation Requirements

  • 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.

Endpoints

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).

Responses

A response for a single animal will have the following format:

{
  "id" : integer,
  "name" : string,
  "species" : string
  "age" : integer
  "breed" : string
  "sex" : string
}

Known Bugs

No known bugs at this time.

License

MIT

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

About

An API for a fictitious animal shelter. This API has full crud functionality, as well as custom endpoints, scopes for searching by different parameters, pagination, CORS, versioning and more.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published