jcubic / wayne

Service Worker Routing library for in browser HTTP requests
https://jcubic.github.io/wayne
MIT License
556 stars 29 forks source link

How to write a POST endpoint would really help #13

Closed rosdec closed 1 year ago

rosdec commented 1 year ago

Ciao,

I'm enjoying your little library but still cannot wrap my mind around an example of using a POST endpoint. You provided plenty of GET examples, and they helped, but POST and how to handle the body would really help.

I'm working on it, when (if) I'll succeed I'll provide a PR!

Best, rosdec

jcubic commented 1 year ago

It's the same as with express:

app.post('/api/validation', function(req, res) {
  req.json().then(json => {
    if (json.data?.length > 0) {
       return res.json({result: true});
    }
    return res.json({result: false});
  });
});
rosdec commented 1 year ago

Hey! Thanks! This was really way easier than I thought.