Establishing an API
Explore how to build an API module in Elixir that interacts with an SQL database by inserting and querying data with Ecto. Learn to structure repository interactions, create changesets for data insertion, and generate aggregated reports by grouping and filtering quiz responses. This lesson helps you understand integrating database operations into your OTP-based Elixir applications.
Let’s move on to the main API at mastery_persistence.ex. For this project, our API exists to save and fetch items from an SQL database. For the most part, our API will consist of Ecto queries that collect and aggregate responses in various ways.
Saving and querying our responses
It’s time to open up /mastery_persistence/lib/mastery_persistence.ex to save and query our responses:
We import Ecto.Query and alias our Repo and Response modules because this file will exist to provide a SQL-focused API to access Mastery responses.