Create a restful API using any framework of choice, which provides an interface for restaurants stored in a database. The API should be self contained and easily runnable.
The exercise implemented on Scala 2.12 with usage only Akka, Akka HTTP, Circe, Lightbend Config and ScalaTest libraries.
URL: /v1/restaurants
Method: POST
Data Parameters in JSON:
- name String
- phone String
- cuisines Array[String]
- address String
- description String
Code: 200
Content: Restaurant entity in JSON format
Example:
curl -H "Content-Type: application/json" \
--data '{"name":"Kyubey","phone":"911","cuisines":["Japan"],"address":"Tokio","description":"The best!"}' \
/v1/restaurants
{"id":1,"name":"Kyubey","phone":"911","cuisines":["Japan"],"address":"Tokio","description":"The best!"}
If one of the required fields is missing:
Code: 400
Content: Error message
URL: /v1/restaurants/:id
Method: PUT
Data Parameters in JSON:
- name String
- phone String
- cuisines Array[String]
- address String
- description String
All fields are optional.
Code: 200
Content: Restaurant entity in JSON format
Example:
curl -H "Content-Type: application/json" -XPUT \
--data '{"address":"Kyoto"}' \
/v1/restaurants/1
{"id":1,"name":"Kyubey","phone":"911","cuisines":["Japan"],"address":"Kyoto","description":"The best!"}
If no restaurant by id is found.
Code: 404
URL: /v1/restaurants/:id
Method: GET
Code: 200
Content: Restaurant entity in JSON format
Example:
curl /v1/restaurants/1
{"id":1,"name":"Kyubey","phone":"911","cuisines":["Japan"],"address":"Tokio","description":"The best!"}
If no restaurant by id is found.
Code: 404
URL: /v1/restaurants
Method: GET
Code: 200
Content: List of restaurant entities in JSON format
Example:
curl /v1/restaurants
[{"id":1,"name":"Kyubey","phone":"911","cuisines":["Japan"],"address":"Tokio","description":"The best!"}]
URL: /v1/restaurants/:id
Method: DELETE
Code: 200
Content: Removed restaurant entity in JSON format
Example:
curl -XDELETE /v1/restaurants/1
{"id":1,"name":"Kyubey","phone":"911","cuisines":["Japan"],"address":"Tokio","description":"The best!"}
URL: /v1/healthcheck
Method: GET
Code: 200
Example:
curl /v1/healthcheck
()
sbt docker:publishLocal
It will build local docker image deliveryhero-test:0.1
docker run -it --rm -p "8080:8080" deliveryhero-test:0.1
By default service bind to 0.0.0.0
interface by 8080
port. It can be changed via environment variables:
- HTTP_HOST
- HTTP_PORT