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

add a form #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add a form #9

wants to merge 1 commit into from

Conversation

brandly
Copy link
Contributor

@brandly brandly commented Mar 17, 2018

right now, POST /links expects JSON data, so here are our options:

  • change endpoint to take name and url from application/x-www-form-urlencoded data, and change <form> to <form action="/links">
  • add some JS to the page to post JSON, but i'd like some way to write a .js file that gets inlined, instead of writing JS in a haskell string. the JS would look something like
document.querySelector('form')
  .addEventListener('submit', function (e) {
    e.preventDefault();
    const body = Array.from(e.target.elements)
      .filter(el => el.type !== 'submit')
      .reduce((out, el) => {
        out[el.name] = el.value
        return out
      }, {});
    fetch('/links', {
      method: 'POST',
      body: JSON.stringify(body)
    }).then(r => {
      if (r.ok) {
        window.location.reload();
      } else {
        console.error(r);
      }
    });
  });

i vote for the first option. we could look at content-type and accept either JSON or form data. i'm not sure how to do these things in haskell, cc @mitchellwrosen

@meangrape
Copy link
Owner

meangrape commented Mar 18, 2018 via email

@mitchellwrosen
Copy link
Contributor

Sure, option 1 sounds good

@mitchellwrosen
Copy link
Contributor

I opened scotty-web/scotty#216 so this is more of a one-liner for us

@meangrape
Copy link
Owner

meangrape commented Mar 18, 2018

I created a new branch, link-form, and merged this PR there. I don't want to merge non-working code into master. We'll keep this open while we resolve things and see how the scotty PR goes.

Thanks, all!

@meangrape
Copy link
Owner

meangrape commented Mar 19, 2018

@brandly Here's a pointer to static content in Scotty. A few years old but looks like a good start.

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.

3 participants