An express app to support CRUD on car model information
- The server stores and retrieves cars model info (make, model and color)
- Supports query on make, model and color
- Uses momngodb
- Pagination supported out of box
- Written in ES6 and babel transpiled
- node
- yarn/ npm
- mongodb
- docker
yarn run build
- All default config can be found in src/config.js
- Secrets should go in .env which now contains docker config
- Anything to override can be modified in .env or set explicitly
- By default app will start at
http://localhost:8000/
- Must start mongodb with command in some other shell. It will listen at port 27017 by default
mongod
- Start the server
yarn run start
For docker the .ev file contains the configuration. Commands
docker-compose build
docker-compose up
-
Car
make
: Required. Type: String.model
: Required. Type: String.color
: Required. Type: Enum. One of [Black, Blue, White, Brown...] (All CSS colours) (Case sensitive)
-
Response Body
errorMsg
: Stringmessage
: String. Present iferrorMsg
not presentbody
: Object. Present iferrorMsg
not present
- Retrieves cars from database.
- Supports query params:
make
,model
,color
,page
- Supports query params example:
/cars?make=Ford&color=White&page=2
- Supported query type is: AND of all fields specifiednd OR of all values of a field, i.e., for make=Ford&make=Subaru&color=White&color=Black, all models which are either [Ford, White], [Ford, Black], [Subaru, White] and [Subaru. Black] will be returned.
- By default it returns page 0
- The count for each page is 10 by default.
- Will return a 404 if page queried is out of bound
- Retieve car by id
/cars/5b6632b7e5f0c52909104905
- The id is to be retieved from the response body of a POST or GET /cars
- Create a car
- JSON accepted
- Combination of make, model, color should be unqiue (Compound index)
- Request body should be:
{ "model" : "ecosport", "make" : "ford", "color" : "Pink" }
- Sample response would be:
{ "message": "Car created", "body": { "_id": "5b6854e2f7b9ef534db67e92", "make": "ford", "model": "ecosport", "color": "Pink", "createdAt": "2018-08-06T14:02:10.606Z", "updatedAt": "2018-08-06T14:02:10.606Z", "__v": 0 } }
- Update a car by id
- Combination of make, model, color should be unqiue (Compound index)
- Request body should be:
{ "model" : "ecosport", "make" : "ford", "color" : "Pink" }
- Returns the updated item in response as
{ "message": "Car updated", "body": { "_id": "5b6854e2f7b9ef534db67e92", "make": "ford", "model": "endeavour", "color": "Black", "createdAt": "2018-08-06T14:02:10.606Z", "updatedAt": "2018-08-06T14:06:40.052Z", "__v": 0 } }
- Modify fields
- Combination of make, model, color should be unqiue (Compound index)
- Example:
{ "model" : "ecosport", "make" : "ford", }
- Returns modified item in response like in PUT
- Delete a car
- ES6/7 is used and babel is used to transpile
- Versioning of API is done
- Supports query of car
- Used supertest for integration test
- Used mongodb for express session storage also
- Cors enabled
- Compound index in db on make, model and color
yarn run test