{"action":"created","issue":{"url":"https://api.github.com/repos/owickstrom/hyper/issues/19","repository_url":"https://api.github.com/repos/owickstrom/hyper","labels_url":"https://api.github.com/repos/owickstrom/hyper/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/owickstrom/hyper/issues/19/comments","events_url":"https://api.github.com/repos/owickstrom/hyper/issues/19/events","html_url":"https://github.com/owickstrom/hyper/issues/19","id":210406200,"number":19,"title":"Type-safe forms","user":{"login":"owickstrom","id":1464328,"avatar_url":"https://avatars1.githubusercontent.com/u/1464328?v=3","gravatar_id":"","url":"https://api.github.com/users/owickstrom","html_url":"https://github.com/owickstrom","followers_url":"https://api.github.com/users/owickstrom/followers","following_url":"https://api.github.com/users/owickstrom/following{/other_user}","gists_url":"https://api.github.com/users/owickstrom/gists{/gist_id}","starred_url":"https://api.github.com/users/owickstrom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owickstrom/subscriptions","organizations_url":"https://api.github.com/users/owickstrom/orgs","repos_url":"https://api.github.com/users/owickstrom/repos","events_url":"https://api.github.com/users/owickstrom/events{/privacy}","received_events_url":"https://api.github.com/users/owickstrom/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-02-27T07:21:36Z","updated_at":"2017-05-17T11:14:38Z","closed_at":"2017-05-17T11:14:38Z","body":"**Goals:**\r\n\r\n* Rendering forms for POST resources with `application/www-form-urlencoded` content type should be type-safe\r\n  - All fields present\r\n  - Correct input types for fields\r\n* Rendered forms should be customizable/extendable in some way, so that the user can add help texts, class attributes, etc\r\n\r\n**Notes:**\r\n\r\nThe current working design does not enforce type-safety, it merely gives you all the input fields with correct types to assemble your form with. Thus, you could override the `type` attribute, omit certain fields, etc. I'm not sure if it is feasible to enforce it without having some type-level Set construct. Anyway, the first attempts will do this less safe approach, and then we can iterate.\r\n\r\nThe idea is to represent forms as such:\r\n\r\n```purescript\r\ntype PersonForm =\r\n  InputHidden \"id\" Int\r\n  :<> InputText \"name\"\r\n  :<> InputNumber \"age\"\r\n```\r\n\r\nAnd then in rendering, do something like:\r\n\r\n```purescript\r\ninstance encodeHTMLNewPerson :: EncodeHTML NewPerson where\r\n  encodeHTML _ =\r\n    case toForms site of\r\n      -- this requires a `ReqBody FormUrlEncoded PersonForm` in the corr routing type\r\n      _ :<|> _ :<|> savePersonForm :<|> _ →\r\n        savePersonForm renderForm\r\n  where\r\n    renderForm (idField :<> nameField :<> ageField) = do\r\n      idField -- automatically type=hidden\r\n      label \"Age\"\r\n      nameField\r\n      label \"Age\"\r\n      ageField -- automatically type=number\r\n```\r\n\r\nAnd have the rendered fields automatically enclosed in a correct `<form>` with `action` and `method` attributes.\r\n\r\nBranch: https://github.com/owickstrom/hyper/tree/type-safe-forms\r\n\r\n**TODO:**\r\n\r\n- [x] (Basic) type-level representation of forms\r\n- [ ] FromFormData/ToFormData type classes\r\n- [ ] Generate extendable markup for forms\r\n- [ ] `ReqBody ct t` for reading, parsing, and passing form data to handlers"},"comment":{"url":"https://api.github.com/repos/owickstrom/hyper/issues/comments/302059530","html_url":"https://github.com/owickstrom/hyper/issues/19#issuecomment-302059530","issue_url":"https://api.github.com/repos/owickstrom/hyper/issues/19","id":302059530,"user":{"login":"owickstrom","id":1464328,"avatar_url":"https://avatars1.githubusercontent.com/u/1464328?v=3","gravatar_id":"","url":"https://api.github.com/users/owickstrom","html_url":"https://github.com/owickstrom","followers_url":"https://api.github.com/users/owickstrom/followers","following_url":"https://api.github.com/users/owickstrom/following{/other_user}","gists_url":"https://api.github.com/users/owickstrom/gists{/gist_id}","starred_url":"https://api.github.com/users/owickstrom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owickstrom/subscriptions","organizations_url":"https://api.github.com/users/owickstrom/orgs","repos_url":"https://api.github.com/users/owickstrom/repos","events_url":"https://api.github.com/users/owickstrom/events{/privacy}","received_events_url":"https://api.github.com/users/owickstrom/received_events","type":"User","site_admin":false},"created_at":"2017-05-17T11:14:38Z","updated_at":"2017-05-17T11:14:38Z","body":"This will most likely be a separate library if realized, so closing this."}}
{"actor":{"display_login":"owickstrom"}}