{"id":17596608,"url":"https://github.com/pauldijou/elm-server","last_synced_at":"2025-03-29T20:14:39.551Z","repository":{"id":145325838,"uuid":"110443598","full_name":"pauldijou/elm-server","owner":"pauldijou","description":"Low level util fonctions","archived":false,"fork":false,"pushed_at":"2017-11-13T22:47:21.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-04T20:43:59.009Z","etag":null,"topics":["elm","elm-lang","server"],"latest_commit_sha":null,"homepage":null,"language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pauldijou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-12T15:24:00.000Z","updated_at":"2017-11-12T15:24:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc85dcbf-485a-43f4-b204-a61c7a2f4a13","html_url":"https://github.com/pauldijou/elm-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldijou%2Felm-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldijou%2Felm-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldijou%2Felm-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldijou%2Felm-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pauldijou","download_url":"https://codeload.github.com/pauldijou/elm-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246237436,"owners_count":20745348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elm","elm-lang","server"],"created_at":"2024-10-22T08:44:50.163Z","updated_at":"2025-03-29T20:14:39.526Z","avatar_url":"https://github.com/pauldijou.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elm-server\n\n:warning: This is probably **not** what you should be using except if you want to write you own server implementation in Elm. Those are low level types and functions to help writing server libs.\n\nIf you need to run Elm on server-side, check one of the following implementations:\n\n- [nomalab/elm-hapi](https://github.com/nomalab/elm-hapi) (based on [Hapi.js](https://hapijs.com))\n- elm-express (based on [Express](https://expressjs.com), coming soon)\n- elm-fastify (based on [fastify](https://www.fastify.io), coming soon)\n\n## Tradeoff\n\nTo ease syntax and boilerplate and improve user experience, this lib can only run one server at a time per Elm worker. This is why you can only start once or again after stopping (start task will fail if you call it again) and you do not have to specify which server you are listening to when subscribing.\n\n## Implement your own server\n\n### Provide a server creator\n\n```elm\nmodule YouCustomServer exposing (..)\n\nimport Json.Decode exposing (Decoder)\nimport Server\n\ntype alias Options = {\n  -- You should put here any options needed to create a raw server\n}\n\ncreate: Options -\u003e Task Error Server.Server\ncreate options =\n  { implementation = Native.YouCustomServer.create options\n  , request =\n    { decoder = requestDecoder\n    }\n  -- other stuff...\n  }\n\nrequestDecoder: Decoder Server.Request\nrequestDecoder =\n  -- you custom request decoder\n```\n\n### ServerImplementation\n\nYou can put whatever you want in your\n\n```javascript\nfunction start({\n  onRequest: function (replier, request) { /* elm-server internals */ }\n}) {\n  // return Promise\u003cServerImplementation\u003e\n}\n\nfunction stop() {\n  // return Promise\n}\n```\n\n### Important concerns\n\nThis will be fixed on Elm 0.19 but as far as 0.18 go, if a `Json.Decode.Decoder` fails, it will call `JSON.stringify` on the value it tried to decode. Since it is JavaScript, the value might be recursive and it will crash at runtime. To prevent that, you need to add a `toJSON` function on any opaque type (`ServerImplementation`, `Replier`) and your request object **before** parsing it.\n\n## License\n\nThis software is licensed under the Apache 2 license, quoted below.\n\nCopyright Paul Dijou ([http://pauldijou.fr](http://pauldijou.fr)).\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this project except in compliance with the License. You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauldijou%2Felm-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpauldijou%2Felm-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauldijou%2Felm-server/lists"}