Skip to content

Add HTTP server example #13

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

Merged
merged 1 commit into from
Dec 25, 2023
Merged

Add HTTP server example #13

merged 1 commit into from
Dec 25, 2023

Conversation

blaix
Copy link
Contributor

@blaix blaix commented Apr 29, 2023

Update: Replaced with a working example now that gren-lang/node#8 is merged.

This is not functional. Looking for feedback on the API.

Main thoughts:

  • Use TEA!
  • Start with the basics.
  • Use the gren/node concept of permissions on init for managed side effects.
  • Just provide the primitives. Other packages can then build on that.


subscriptions : Model -> Sub Msg
subscriptions model =
Http.onRequest model.serverKey HandleRequest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, we might have different subscription functions that specialises over the requests body type. Examples Http.onJsonRequest or Http.onStreamRequest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better for that to be handled with a custom type on body?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends. But for Stream and Byte specifically: Stream represents an asynchronous stream of bytes. You cannot just call a function on it and get JSON out, you'll need to handle it in a task or through some other means. For Byte however, you can convert it directly to JSON.

@robinheghan
Copy link
Member

Added a few comments, but ultimately think you're on the right path :)

blaix added a commit to blaix/example-projects that referenced this pull request Apr 30, 2023
Starting a server can fail. Get a Permission on init (like FileSystem)
and return a Task to handle failure.

Based on feedback from the PR:
gren-lang#13
@blaix
Copy link
Contributor Author

blaix commented Apr 30, 2023

Updated based on feedback

@robinheghan
Copy link
Member

Just looked over your latest changes and I think it looks good. Might want to add a id or key value to the Request record in order to tell two requests apart, but other than that it's good 👍

@blaix
Copy link
Contributor Author

blaix commented May 10, 2023

Iterating on this API and chipping away at implementation here: blaix/gren-node#1

@blaix blaix force-pushed the http-server branch 2 times, most recently from 6e69b7a to de8f384 Compare December 24, 2023 19:50
@blaix blaix marked this pull request as ready for review December 24, 2023 19:57
@blaix blaix changed the title Initial API idea for a node http server in gren Add HTTP server example Dec 24, 2023
@blaix
Copy link
Contributor Author

blaix commented Dec 25, 2023

Finally updated this with a working example now that the HTTP server API is merged in.

@robinheghan robinheghan merged commit 7bb41ed into gren-lang:main Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants