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.
- Clone this repository:
git clone https://github.com/your_username/cat_images_api.git
- Install dependencies:
cd cat_images_api && bundle install
- Set up the database:
rails db:setup
- Run the server:
rails server
- Docker
-
Clone the repository:
git clone <repository-url> cd <repository-folder>
-
Build the Docker image:
docker build -t <image-name> .
-
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. -
Access the application in your web browser by visiting
http://localhost:<port>
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"
}
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 /cats/:id
Response:
HTTP/1.1 204 No Content
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"
}
]
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"
}
To run the tests, run the following command:
rspec
This will run the RSpec test suite and output the results in the terminal.
This project is licensed under the MIT License.