write notes on how to run docker compose in background and only view logs for node app since it's noisy
This RESTful API provides as CRUD interface to store and access Cat Pics. (We do not validate that this is a cat pic, honor system š¤«)
Some technical specifications:
- The project is running on NodeJs
- The API layer is powered by Expressjs
- The database of choice here is MongoDb
- The middleware for handling
multipart/form-data
is Multer. - The storage engine in MongoDb for images is GridFS
After you have cloned this repo locally, there are two ways of getting up and running:
To run this locally, you will first need mongoDb up and running.
- run
npm install
- create a file called
.env
- copy over the contents of
.env.example
and update as necessary - run
npm run dev
Local development does provide hot-reloading on changes.
- run
docker compose up --build
the first time - after that
docker compose up
should do the trick
The log from MongoDb can get a little noisy, here's an alternative to follow only the catpixly-api logs:
- run
docker compose build
if you haven't yet - run
docker compose up -d
to run docker compose in the background - run
docker logs catpixly-api -f
to follow only catpixly-api logs - run
docker compose down
when done
A postman collection is provided in this repo in the postman folder.
You will need to import both the ...collection.json
and ...environment.json
.
Method | Endpoint | Headers | Request Parameters | Request Body | Response | Response Status Code |
---|---|---|---|---|---|---|
GET | /images/all | N/A | N/A | N/A | An array of Images Object | 200 OK |
POST | /images/image/ | Content-Type = multipart/form-data | N/A | catPic = Image | Image Object | 200 OK |
GET | /images/image/:id/ | N/A | id = Image Id | N/A | Image Object | 200 OK |
PUT | /images/image/:id/ | Content-Type = multipart/form-data | id = Image Id | catPic = Image | String | 200 OK |
DELETE | /images/image/:id/ | N/A | id = Image Id | N/A | N/A | 204 No content |
GET | /images/file/:id/ | N/A | id = Image Id | N/A | Readable Stream | 200 OK |
A proper path to test this API would look like:
- Add Image To Db x2
- Inside
Body
, select the file to upload - This will automatically store the most recent id in a variable
recentImageId
- Inside
- Get All Images
- Get Image By Id
- Uses the Id stored in
recentImageId
from thePOST
to Add Image
- Uses the Id stored in
- Get Image File By Id
- Uses
recentImageId
- Uses
- Update Image By Id
- Inside
Body
, select the file to upload - Uses
recentImageId
- Inside
- Delete Image By Id
- Uses
recentImageId
- Uses
There is also a low-code landing page at http://localhost:3000/
to help upload images, although it does to fetch them too.
-
Testing (probably with Jest)
-
Better frontend, with React
-
Swagger docs for API spec instead of markdown
-
Auth
-
Better error handling and logging
-
Maybe a way to join the two collections so we do not have Images and Uploads to keep track of.
TODO: Learn multer and multipart form data, gridfs