A simple api gateway demostration using the serverless framwork to build a simple backend in AWS.
The API can handle new orders and dislay the latest (max 5) orders of the user.
Creates a new order if does not exist, if exists it returns a warning that it exists already and does not alter the database.
Each order should have:
- store_id: String
- order_id: String
- user_id: String
- grand_total : Number
**Sample Request body** :
{
"store_id" : "store01",
"order_id":"order01",
"user_id": "user01",
"grand_total" : 110.00
}
Expected returns
- Order is new
{
"statusCode": 201,
"body": {
"message": "Order order01 submitted successfully"
}
}
- Order already exists (error)
{
"statusCode": 400,
"error": "The conditional request failed"
}
Returns the last 5 orders of the given user .
Each request should have:
- user_id : String
- store_id : String
Sample Request body:
{
"user_id": "user1",
"store_id": "store1"
}
Sample Expected returns
- User has ordered before
{
"statusCode": 200,
"orders": [
{
"user_id": "user1",
"grand_total": 110,
"order_id": "order8",
"store_id": "store1",
"timestamp": "user1#1544092158240"
},
{
"user_id": "user1",
"grand_total": 110,
"order_id": "order7",
"store_id": "store1",
"timestamp": "user1#1544092152000"
},
{
"user_id": "user1",
"grand_total": 110,
"order_id": "order6",
"store_id": "store1",
"timestamp": "user1#1544092147627"
},
{
"user_id": "user1",
"grand_total": 110,
"order_id": "order5",
"store_id": "store1",
"timestamp": "user1#1544092143040"
},
{
"user_id": "user1",
"grand_total": 110,
"order_id": "order4",
"store_id": "store1",
"timestamp": "user1#1544092138603"
}
],
"body": {
"message": "Orders retrieved successfully"
}
}
- User does'nt have any orders (error)
{
"statusCode": 400,
"error": "User user1 has no orders yet !"
}