An example web service project with CRUD and RPC style endpoints.
This is a demonstration project only. It is not ready to be used in production.
This code is available in the following languages:
This project will randomly generate shop stock from a list of items in a database.
The service provides CRUD (POST, GET, PUT, DELETE) endpoints for items within the /api/items resource.
An item is made up of some description and multiple possible prices so that they can be allocated to multiple shops.
Note Item prices have types. This is not currently used but is here to show how I would expand the program next.
An item can be represented using this JSON string:
{
"name": "A Shiny Item",
"description": "I am really shiny.",
"prices": [
{
"type": "basic",
"value": 12345
}
]
}Shops are randomly generated lists of items based on some criteria.
You will need to know:
- Which RNG method to use:
randuses the inbuilt random functions.lcguses a quick LCG that I wrote.
- A
seedfor our random number generation. - What our minimum (min) price is.
- What our maximum (max) price is.
- The maximum number of items we want in our shop (num_items).
To generate a shop first, make sure you have added some items to the database.
Then, you should make the following request:
POST /api/shop
Content-Type: application/json
Accept: application/json
{
"rng": {
"method": "rand",
"seed": 123456
},
"price": {
"min": 1,
"max": 20
},
"num_items": 10
}You should receive a JSON object containing your shop details, items and prices.
I wanted an unusual project to demonstrate that I know how to:
- Demonstrate a solution to unusual problems.
- Use framework conventions.
- Employ the use of different HTTP methods.
- Write Feature and Unit tests.
- (Hopefully) write a decent README :).
It doesn't demonstrate that I know how to:
- Publish a package for others to use.
- Write a CLI app.
That's because of the current size and I have other (older) examples for those.
In order to install and run the app, please pick one of the versions listed here.
They will have their own unique setup instructions.
This project is published under the MIT license.
Full details can be found in the "LICENSE" file.