Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would you handle HTTP requests? #67

Open
8483 opened this issue Dec 8, 2018 · 4 comments
Open

How would you handle HTTP requests? #67

8483 opened this issue Dec 8, 2018 · 4 comments

Comments

@8483
Copy link

8483 commented Dec 8, 2018

The ELM Architecture handles HTTP requests outside of the mount function, as it considers them impure.

Do we simply execute the request inside of the update switch statement i.e. break the pattern?

@nelsonic
Copy link
Member

nelsonic commented Dec 8, 2018

@8483 could you please share a bit more detail about your HTTP request?
Are you sending/requesting data from a server/service?
Elm typically does this with a Task. in JS land we would need to create an event listener.

@8483
Copy link
Author

8483 commented Dec 8, 2018

@nelsonic That was a quick response. :)

Yes, I am talking about getting data from a RESTful API and updating the model with the response data.

Task and Command were always confusing for me compared to Message. I still don't fully understand why they are required and what the difference is.

As far as I got it, commands are used as a message sent after a message, and tasks as handling impure things.

It would be cool if they were explained via a Javascript example, but sadly, I am unable to contribute the explanation as I don't fully grasp them.

@nelsonic
Copy link
Member

nelsonic commented Dec 8, 2018

@8483 your understanding of Task, Command and Message are good. ✅
I tend to agree that in some cases explaining Elm Architecture concepts in JS is useful for people who have good JS knowledge/experience. But I think Evan is pitching his guide/language at people who aren't JS experienced ... 🤔

@w-h-a
Copy link

w-h-a commented Aug 3, 2021

For what it is worth, I would definitely be interested in seeing the elmish Todo app expanded to elmishly talk to APIs/servers with vanilla JS. What would elm commands look like in the vanilla JS elmish Todo app? Would we also have to add on to elmish.js or perhaps make our own Http.js and JSON.js (for encoding form inputs) modules? I don't know if there's still any interest in this, but I would love to see something like that here. Following the tutorial so far has been very useful for me. If anyone knows of a similar elmish tutorial that also covers API/server communication, that would also interest me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants