This API interacts with a database, containing information used for the tea selector app.
- gorilla/mux -
go get -u github.com/gorilla/mux
To build an executable, run:
go build
The config.yml
file gives an example configuration. This can be changed to your liking. You MUST set the value of signingkey
, and the port
to be used. Optionally, you can also:
- Enable the endpoint
POST /register
. - Set the database location.
- Set the default tea types and owners.
Additionally, tea-store.sql
is included to setup an example database. To use it, run sqlite3 tea-store.db
, and then .read tea-store.sql
.
By default, the API will be running on localhost:7344
.
-
To login, send a POST request to
/login
with the body:{ "username": "YourUsername", "password": "YourPassword" }
-
To register (if enabled), send a POST request to
/register
with the body:{ "username": "NewUsername", "password": "NewPassword" }
-
To change the password, send a POST request to
/changepassword
with the body:{ "old": "YourOldPassword", "new": "YourNewPassword" }
Note: This will only work if you're already authorized.
-
To see all current tea types, send a GET request to
/types
-
To see all teas of all types, send a GET request to
/types/teas
-
To get information about a tea type, send a GET request:
/type/{id}
-
To add a new tea type, send a POST request to
/type
. An example body is:{ "name": "Black Tea" }
-
To delete a tea type, send a DELETE request:
/type/{id}
-
To see all current owners, send a GET request to
/owners
-
To see all teas for every owner, send a GET request to
/owners/teas
-
To get information about an owner, send a GET request:
/owner/{id}
-
To add a new owner, send a POST request to
/owner
. An example body is:{ "name": "John" }
-
To delete an owner, send a DELETE request:
/owner/{id}
-
To see all teas, send a GET request to
/teas
-
To get information about a tea, send a GET request:
/tea/{id}
-
To add a new tea, send a POST request to
/tea
. An example body is:{ "name": "Snowball", "type": { "id": 1 } }
-
To delete a tea, send a DELETE request to
/tea/{id}
-
To see all teas with all their owners, send a GET request to
/teas/owners/
-
To see the owners for a specific tea, send a GET request:
/tea/{id}/owners
-
To add an owner, send a POST request to
/tea/{id}/owner
. An example body is:{ "id": 1 }
-
Tp delete an owner from a tea, send a DELETE request to
/tea/{teaID}/owner/{ownerID}