![]() In the Ecto guide, we saw how we can use Changesets and Repos to validate and persist user schemas, but we didn't integrate this with our application at large. In order to run the context generators, we need to come up with a module name that groups the related functionality that we're building. Let's put these tools to use for our new product catalog context. ![]() These generators are a great way to hit the ground running while Phoenix nudges you in the right direction to grow your application. Phoenix includes the mix, mix, mix, and mix generators that apply the ideas of isolating functionality in our applications into contexts. We'll see how starting with a solid foundation with isolated boundaries allows us to grow our application naturally as we add functionality. We'll start off with the basic features of showcasing our products, and we will add shopping cart features later. With that in mind, our goal is to build a product catalog API that handles creating, updating, and deleting the products available in our system. This guide focuses on those readers.Īn ecommerce platform has wide-reaching coupling across a codebase so it's important to think upfront about writing well-defined interfaces. How to read this guide: Using the context generators is a great way for beginners and intermediate Elixir programmers alike to get up and running quickly while thoughtfully designing their applications. Our goal is to build an ecommerce system where we can showcase products, allow users to add products to their cart, and complete their orders. Let's use these ideas to build out our web application. Overall, think of them as boundaries to decouple and isolate parts of your application. In Phoenix, contexts often encapsulate data access and data validation. At the end of the day, contexts are just modules, as are your controllers, views, etc. We call the Logger module the context, exactly because it exposes and groups all of the logging functionality.īy giving modules that expose and group related functionality the name contexts, we help developers identify these patterns and talk about them. Internally, Elixir's logger is made of multiple modules, but we never interact with those modules directly. For example, anytime you call Elixir's standard library, be it /1 or Stream.map/2, you are accessing different contexts. In other words, it's vital to think about application design when writing code.Ĭontexts are dedicated modules that expose and group related functionality. We need to consider the boundaries between modules and how to group functionality. Naturally, we compose our applications with modules and functions, but simply defining a module with a few functions isn't enough when designing an application. Phoenix's job is to provide a web interface into our Elixir application. ![]() ![]() When building a Phoenix project, we are first and foremost building an Elixir application. Now it's time to tie it all together by writing web-facing features that interact with our greater Elixir application. So far, we've built pages, wired up controller actions through our routers, and learned how Ecto allows data to be validated and persisted. Requirement: This guide expects that you have gone through the Ecto guide. Requirement: This guide expects that you have gone through the Request life-cycle guide. Requirement: This guide expects that you have gone through the introductory guides and got a Phoenix application up and running. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |