# I built a nice Rest API with Elm (experiment)

**URL:** <https://discourse.elm-lang.org/t/i-built-a-nice-rest-api-with-elm-experiment/7308>\
**Category:** Request Feedback\
**Created:** [April 29, 2021, 8:06am UTC](https://discourse.elm-lang.org/t/i-built-a-nice-rest-api-with-elm-experiment/7308 "2021-04-29T08:06:27Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![rupert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rupert/32/1775_2.png) [@rupert](https://discourse.elm-lang.org/u/rupert)\
**Post date:** [May 10, 2021, 7:38pm UTC](https://discourse.elm-lang.org/t/i-built-a-nice-rest-api-with-elm-experiment/7308/21 "2021-05-10T19:38:21Z")

</div>

> [@Atlewee](#):
>
> If you use the elm server as an aggregate/materialized view in an event sourced system, you do not even talk to a database or file system on requests. It just reads old events/msgs on init and builds an in memory data model that can be queried, updating it on every event/msg.

I am not criticising this idea - I love the thinking and its definitely worth exploring - but I wanted to point out why it won’t work for the `elm-serverless` use case.

Basically, with AWS Lambda functions you have no control over the lifecycle of the underlying runtime. Which is kinda the point, you let AWS figure that out for you. But it means that you cannot guarantee your runtime will stick around for any length of time. So if I read all the events into memory ready to be queried, I could process just 1 request, and then the whole thing gets chucked away and needs to be re-done for the next request.

Not sure, but maybe AWS provides a way to hook into the init phase of a Lambda to do the event loading. If requests are coming in fast enough I think AWS will manage to keep the same runtime alive to process many - so perhaps this idea not a complete dead end.

It would be nice if I didn’t have to use a database, but so far my Elm AWS Lambda functions have tended to involve mutiple sequential IO operations. Which is why I have been looking at the `elm-procedure` way of doing things with a lot of interest.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [May 20, 2021, 7:38pm UTC](https://discourse.elm-lang.org/t/i-built-a-nice-rest-api-with-elm-experiment/7308/22 "2021-05-20T19:38:44Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.elm-lang.org/t/i-built-a-nice-rest-api-with-elm-experiment/7308.md?page=1)
