📎 Webclip
Test-Driven APIs with Phoenix and Elixir
The tutorial builds an API by starting with a failing integration test and changing the code only when the test points to what is missing. It shows how that process helps the author understand Phoenix and Elixir components while adding the movies endpoint.
Reading notes#
- Start a new Phoenix project without HTML and Brunch because the goal is an API, not pages or stylesheets.
- Create the first integration test for a GET request to /movies and use the failures to discover what needs to be added next.
- Add Plug.Test, a router call, a route for /movies, a controller, and a view until the endpoint returns a response.
- Add a Movie model with name and rating, then use the generator and migrations to make the struct available in the test.
- Encode the movie and the controller output with Poison so the response becomes valid JSON instead of a raw struct.
- Update the integration test to compare the response with the encoded movie list.
- Fix the error view tests so JSON error rendering matches the expected map shape.
- The article closes by saying that TDD gives fast feedback and helps move forward more confidently when learning new tools.
