Simple test of api rest without dependencies, but in memory
- No third-party
packages/dependencies
- You can use curl or a
http
client for requests
- Go stable version
-
GET /shirts
returns list of shirts as JSON -
GET /shirts/{id}
returns details of specific shirt as JSON -
POST /shirts
accepts a new shirt to be added -
POST /shirts
returns status 415 if content is notapplication/json
-
GET /admin
requires basic auth -
GET /shirts/random
redirects (Status 302) to a random shirt
A shirt object should look like this:
{
"id" : "0001",
"material" : "Lana",
"class" : "Manga Larga",
"size" : 14,
}
Note: If you are using pwsh, please note this
- First configure the password, then run
go run server.go
> $env:ADMIN_PASSWORD = 'secret'
- Or just run
> ADMIN_PASSWORD='secret' go run server.go
- To test basic authentication
> curl localhost:3000/admin -u admin:secret
- Remember that you will have to add new data at each restart
There is no persistence of data, a memory time is fine.