``` [build] kill_delay = "1s" send_interrupt = true ``` ## Get Movie ```bash curl -i http://0.0.0.0:5002/v1/movies/1 ``` ## Creating a movie ```bash curl -i -X POST -d '{"title":"Passengers","year":2016,"runtime":"120 mins", "genres":["comedy","adventure"]}' http://0.0.0.0:5002/v1/movies ``` ```bash curl -i -X POST -d '{"title":"Mortal Engines","year":2019,"runtime":"130 mins", "genres":["sci-fi","adventure"]}' http://0.0.0.0:5002/v1/movies curl -i -X POST -d '{"title":"Everything Everywhere All at Once","year":2023,"runtime":"135 mins", "genres":["sci-fi","adventure"]}' http://0.0.0.0:5002/v1/movies curl -i -X POST -d '{"title":"Renfield","year":2023,"runtime":"115 mins", "genres":["comedy","adventure"]}' http://0.0.0.0:5002/v1/movies curl -i -X POST -d '{"title":"Mad Max Fury Road","year":2015,"runtime":"145 mins", "genres":["action","adventure", "sci-fi"]}' http://0.0.0.0:5002/v1/movies curl -i -X POST -d '{"title":"Immortals","year":2011,"runtime":"135 mins", "genres":["action","adventure", "fantasy"]}' http://0.0.0.0:5002/v1/movies curl -i -X POST -d '{"title":"Patlabor","year":1992,"runtime":"125 mins", "genres":["anime","sci-fi"]}' http://0.0.0.0:5002/v1/movies ``` ```bash curl -i -X POST -d '{"title":"The Batman","year":2022,"runtime":"177 mins", "genres":["action","adventure"]}' http://0.0.0.0:5002/v1/movies ``` ```bash curl -i -X POST -d '{"title":"Death of a Unicorn","year":2025,"runtime":"126 mins", "genres":["comedy","satire"]}' http://0.0.0.0:5002/v1/movies ``` ```bash BODY='{"title":"Black Panther","year":2018,"runtime":"134 mins","genres":["sci-fi","action","adventure"]}' curl -X PUT -d "$BODY" http://0.0.0.0:5002/v1/movies/1 ``` ## Sorting by items REMEMBER: you have to quote strings that contain & ```bash curl http://localhost:5002/v1/movies?genres=comedy&sort=-year ``` ```text "time":"2026-02-08T11:35:42.782856326-05:00","level":"DEBUG","source":{"function":"main.(*application).listMoviesHandler","file":"/home/toor/workspace/pulley/cmd/api/handlers.go","line":247},"msg":"query params","qp":{"genres":["comedy"]}} ``` ```bash curl "http://localhost:5002/v1/movies?genres=comedy&sort=-year" ``` ```text {"time":"2026-02-08T11:38:52.253316749-05:00","level":"DEBUG","source":{"function":"main.(*application).listMoviesHandler","file":"/home/toor/workspace/pulley/cmd/api/handlers.go","line":247},"msg":"query params","qp":{"genres":["comedy"],"sort":["-year"]}} ``` ## Generating an Update Conflict We can try to use the xargs tool to submit multiple requests to our webserver. Hopefully this results in the 409 that we are looking to create. ```bash xargs -I % -P8 curl -X PATCH -d '{"runtime": "97 mins"}' "localhost:5002/v1/movies/4" < <(printf '%s\n' {1..8}) ``` ## Adding Time Taken To You Curl Request Use the `-w` to anotate the response `https://blog.josephscott.org/2011/10/14/timing-details-with-curl/` ```bash curl -w '\nTime: %{time_total}s \n' localhost:5002/v1/movies/4 { "movie": { "id": 4, "title": "The Batman", "year": 2021, "Runtime": "97 mins", "genres": [ "action", "adventure" ], "version": 5 } } Time: 8.009385s ``` ## Timeout a Curl Request We can timeout our curl request like so ```bash curl --max-time 2 localhost:5002/v1/movies/4 ``` ## Migrations Don't forget that the migrate tool can be used to create the stub of your index files. ```bash migrate create -seq -ext .sql -dir ./migrations add_movies_indexes ``` To run migrations from the cmdline you need to have the pgx5 installed ```bash go install -tags 'pgx5' github.com/golang-migrate/migrate/v4/cmd/migrate@latest ``` Then you need to specify a database uri ```bash migrate -dir ./migrations -database "pgx://pulley:pulley@localhost:5434/pulley" goto 2 ``` ## Postgres en.wikipedia.org/wiki/Stemming We are using the postgres simple type for full text search but we could use some of the more advanced options for this like english. This will perform stemming for us and resulting in common words like "a" or "the" from appearing in the lexemes it generates. Check out `\dF` for all the available configurations. See the docs for more about full text search. https://www.postgresql.org/docs/current/textsearch.html ### Other Resources - https://niallburkley.com/blog/index-columns-for-like-in-postgres/