webapp.py comprises a simple web application to host assets such that:
- Every asset that we store has an "asset name". There are some rules about asset names:
- They must be globally unique across all assets
- They can only contain alphanumeric ascii characters, underscores, and dashes
- They cannot start with an underscore or dash
- They must be between 4 and 64 characters long
- Every asset has an "asset type" which is a string that must either be "satellite" or "antenna".
- Every asset has an "asset class" which depends on its asset type and is a string. For "satellite" assets it can be "dove" or "rapideye". For "antenna" assets it can be "dish" or "yagi".
- Users can create assets. To do so, they must supply the asset name, asset type, and asset class.
- Users can retrieve the whole list of assets.
- Users can retrieve a single asset by name.
- An asset cannot be deleted. Also its name, type, and class cannot be changed.
Before you begin, install requirements:
$ pip install [--user] -r requirements.txt
You may also run unit tests with py.test
or nosetests
.
Upon executing the below command, a web server will be listening on port 8080, ready to handle requests for assets.
$ python webapp.py 8080
Command-line use-cases are provided below.
Gets a list of all assets, one-per-line and urlencoded.
$ curl -i http://0.0.0.0:8080/
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Sat, 10 Jun 2017 09:29:14 GMT
Server: localhost
name=aaaa&type=satellite&class=dove
name=aaab&type=antenna&class=dish
Gets a specific urlencoded asset.
$ curl -i http://0.0.0.0:8080/aaaa
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Sat, 10 Jun 2017 09:30:54 GMT
Server: localhost
name=aaaa&type=satellite&class=dove
Create an asset at /{name}
$ curl -X PUT -d "name=aaaa&type=satellite&class=dove" -i http://0.0.0.0:8080/aaaa
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Sat, 10 Jun 2017 09:32:29 GMT
Server: localhost
name=aaaa&type=satellite&class=dove
Subsequent calls to PUT /{name} where {name} already exists will return a 403 Forbidden error, e.g.
$ curl -X PUT -d "name=aaaa&type=satellite&class=dove" -i http://0.0.0.0:8080/aaaa
HTTP/1.1 403 Forbidden
Content-Type: text/html
Transfer-Encoding: chunked
Date: Sat, 10 Jun 2017 10:38:25 GMT
Server: localhost
forbidden
``