Simply install go 1.17 or newer.
cd to 'tomapi' directory
docker build -t tomapi-prod -f Dockerfile.production .
docker ru
8000
n -it -p 8084:8084 tomapi-prod
docker tag tomapi-prod:latest tsasser05/tomapi:tomapi-prod
docker push tsasser05/tomapi:latest
I recommend you use Postman to test the API, though curl commands are included below.
brew install sqllite sqlite-utils
Create the names.db file once. The file will be included in the docker build.
sqlite3 names.db
sqlite> CREATE TABLE [names] (
...> id INTEGER NOT NULL PRIMARY KEY,
...> first_name TEXT NOT NULL,
...> last_name TEXT NOT NULL
...> );
sqlite> insert into names values
...> (NULL, "Peter","Parker");
sqlite> insert into names values
...> (NULL, "Foo","Bar");
h3. Verify
sqlite-utils names.db "select * from names" --table
id first_name last_name
---- ------------ -----------
1 Peter Parker
2 Foo Bar
If you want to run the app on the CLI to test it, then run:
go run main.go
HTTP Op | Description |
---|---|
GET | Get a list of all names, returned in JSON format |
POST | Add a name from request data sent as JSON |
HTTP Op | Description |
---|---|
GET | Get a name by first name, returning data in JSON format |
HTTP Op | Description |
---|---|
PATCH | Edit a name by database ID, first_name and/or last_name, submitted in JSON format |
DELETE | Delete a name by database ID |
curl --location --request GET 'http://localhost:8084/names'
curl --location --request POST 'http://localhost:8084/names' \
--header 'Content-Type: application/json' \
--data-raw '{
"first_name": "Baz",
"last_name": "Boo"
}'
curl --location --request GET 'http://localhost:8084/names/Baz'
Try finding a name that is not in the database:
curl --location --request GET 'http://localhost:8084/names/Foo'
Do a GET first to find the ID.
curl --location --request GET 'http://localhost:8084/names'
Update the record:
curl --location --request PATCH 'http://localhost:8084/names/2' \
--header 'Content-Type: application/json' \
--data-raw '{
"first_name": "Baz",
"last_name": "Boo"
}'
Do a GET first to find the ID.
curl --location --request DELETE 'http://localhost:8084/names/2'