Numbers API

A small API for working with numbers, built for learning how APIs work. See the API reference for every parameter, response and error.

Add

Adds two numbers.

/add?a=3&b=4

Fibs

Generates Fibonacci numbers.

/fibs?a=3&b=4&n=10

/fibs?n=5&format=json

Random

Generates random numbers between min and max.

/random?min=1&max=6&count=10

/random?count=3&format=json

Range

Generates a range of numbers.

$ curl -H 'Content-Type: application/json' \
    -d '{"start": 1, "stop": 10, "step": 2}' \
    http://127.0.0.1:7001/range
{"result":[1,3,5,7,9]}

Product, Sum, Average, Sort

Multiply, add, average or sort a list of numbers.

$ curl -H 'Content-Type: application/json' \
    -d '{"numbers": [5, 4, 3, 2, 1]}' \
    http://127.0.0.1:7001/product
{"result":120}

Replace /product with /sum, /average or /sort.

Stats

Count, sum, mean, min and max of a list of numbers.

$ curl -H 'Content-Type: application/json' \
    -d '{"numbers": [1, 2, 3, 4, 5]}' \
    http://127.0.0.1:7001/stats
{"count":5,"sum":15,"mean":3.0,"min":1,"max":5}

Me

Tells you who your token belongs to. A token is your username followed by -token-123, e.g. alice-token-123.

$ curl -H 'Authorization: Bearer alice-token-123' http://127.0.0.1:7001/me
{"username":"alice"}

Store

Save numbers under a name. Every user has their own store.

$ AUTH='Authorization: Bearer alice-token-123'

$ curl -H "$AUTH" -H 'Content-Type: application/json' \
    -d '{"value": 42}' http://127.0.0.1:7001/store/x
{"value":42}

$ curl -X PUT -H "$AUTH" -H 'Content-Type: application/json' \
    -d '{"value": 43}' http://127.0.0.1:7001/store/x
{"value":43}

$ curl -H "$AUTH" http://127.0.0.1:7001/store/x
{"value":43}

$ curl -H "$AUTH" http://127.0.0.1:7001/store
{"x":43}

$ curl -X DELETE -H "$AUTH" http://127.0.0.1:7001/store/x
{"ok":true}