How to Fetch Survey Results Data

Learn how to fetch data from an API in a Phoenix LiveView in this lesson.

To go much further, we’re going to need data, so we’ll switch gears from the view and focus on the backend service. In order to render products and their average star ratings in a chart, the LiveView must be able to query for this data in the form of a list of product names and their associated average star ratings.

This will be a good time to practice good Phoenix design. We’ll add a new API function to the Catalog context to make requests to the database. Our context function will rely on new query functions in the core to extract exactly the data it needs. Separating these concerns will keep the codebase organized and beautiful.

Get hands-on with 1200+ tech skills courses.