Let’s move the code for fetching and displaying all posts to a new module. Create a new directory called Page inside post-app and add a file named ListPosts.elm to it.
Add the following code to ListPosts.elm.
Creating the Main Module
We moved almost all of the code from DecodingJson.elm to either ListPosts.elm or Post.elm. The only thing remaining is the main function. Where should we put it? It too should have its own module. Create a new file called Main.elm in the post-app directory and add the following code to it.
Right now the Main module relies heavily on the ListPosts page. In the next section, we’ll give it its own Model, Msg, init, view, and update functions so that it’s not tightly coupled to any specific module. Going forward, the primary responsibility of Main will be to route users to the correct page.
Before moving on, let’s make sure everything is working. Run json-server from the beginning-elm directory in terminal using the following command.
Now run elm reactor from the beginning-elm directory in a different terminal window and go to this URL in your browser: http://localhost:8000/post-app/Main.elm. You should see a list of posts.