Skip to content

Latest commit

 

History

History
149 lines (104 loc) · 2.43 KB

README.md

File metadata and controls

149 lines (104 loc) · 2.43 KB

Cats API

This is a simple REST API for uploading, deleting, fetching, and listing cat images. It's built using Ruby on Rails and supports JSON responses.

Installation

  1. Clone this repository: git clone https://github.com/your_username/cat_images_api.git
  2. Install dependencies: cd cat_images_api && bundle install
  3. Set up the database: rails db:setup
  4. Run the server: rails server

Docker

Prerequisites

  • Docker

Build and Run

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-folder>
    
  2. Build the Docker image:

    docker build -t <image-name> .
    
  3. Run the Docker container:

    docker run -p <port>:<port> -d --name <container-name> <image-name>
    

    Replace <port> with the desired port number, <image-name> with the name you gave to the Docker image in step 2, and <container-name> with a name of your choice for the container.

  4. Access the application in your web browser by visiting http://localhost:<port>

Usage

Upload a cat image

POST /cats

Headers:
Content-Type: multipart/form-data

Parameters:
name: string (required)
image: file (required)

Response:
HTTP/1.1 201 Created
Content-Type: application/json

{
  "id": 1,
  "name": "Cato",
  "image_url": "http://localhost:3000/cats/1/image"
}

Fetch a cat image

GET /cats/:id/image

Response:
HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Disposition: inline; filename="cat.jpg"
Content-Length: 150812

<cat image binary data>

Delete a cat image

DELETE /cats/:id

Response:
HTTP/1.1 204 No Content

List all cat images

GET /cats

Response:
HTTP/1.1 200 OK
Content-Type: application/json

[
  {
    "id": 1,
    "name": "Cato",
    "image_url": "http://localhost:3000/cats/1/image"
  },
  {
    "id": 2,
    "name": "Mittens",
    "image_url": "http://localhost:3000/cats/2/image"
  }
]

Update a cat image

PATCH /cats/:id

Headers:
Content-Type: application/json

Parameters:
name: string (optional)
image: file (optional)

Response:
HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 1,
  "name": "Cato Updated",
  "image_url": "http://localhost:3000/cats/1/image"
}

Testing

To run the tests, run the following command:

rspec

This will run the RSpec test suite and output the results in the terminal.

License

This project is licensed under the MIT License.