resource-router-middleware icon indicating copy to clipboard operation
resource-router-middleware copied to clipboard

Improve documentation

Open maayanorner opened this issue 7 years ago • 5 comments

I think the documentation could be improved, I'm using your boilerplate REST API and this (great) module is rather confusing to me. I think what it really lacks is a small explanation about the motivation and some example implementing models as well. I would happily do it but I don't really understand it fully. Is there any chance you can give a little more details in general? Also, an example how models would look like will be helpful as well. I hope I'm not asking too much :P but I did try to dig into the code, and still quite complicated for me.

Thank you!

maayanorner avatar Jun 03 '18 12:06 maayanorner

@maayanorner Did you figure it out? I'm now where you were ~2 months ago 😅

Do you think you could provide a more complete example/rationale? Seems like magic to me how create() and read() are just mapped to POST and GET, I can't say if this pattern would end up being problematic when I dive deeper into more customized use cases.

Aditya94A avatar Jul 28 '18 03:07 Aditya94A

I don't truly understand how it works, even though it's not even that much to read, but I got it working. Hopefully these examples will be helpful to someone trying to use this with Mongoose.

In my example I have a simple user object that stores an id (different from MongoDB "_id"), a latitude value, and a longitude value.

My db.js file where I init the database: https://gist.github.com/Dylan-at-LION/e861cd4ebc8d2f6a9ebbdc105c17f0c0

My model file stored as models/user.js next to facets.js example: https://gist.github.com/Dylan-at-LION/b9acd52b5baf4e7a205015c79e955177

My api/index.js file where I register the routes: https://gist.github.com/Dylan-at-LION/c7443fa8dbf99dcf60a55b730874b4bd

And finally my api/users.js where the magic happens: https://gist.github.com/Dylan-at-LION/dcde3cb9d91d49a40c17e19569d3ba24

This is a mysterious little tool but it's pretty amazing once you get it. I don't see how it would limit you very much, it just forces you into a smart pattern that is widely applicable.

Dylan-Wells-at-LION avatar Aug 14 '18 22:08 Dylan-Wells-at-LION

Did anyone figure out how to write a test cases with it though?

serain avatar Nov 26 '18 21:11 serain

@serain Use an HTTP testing tool like supertest.

developit avatar Nov 26 '18 21:11 developit

Thanks for the kind words @Dylan-at-LION :) If you're up for it, we could probably add a wiki page with your last gist link explaining how to wire this up to Mongoose. I may have a full example application I can publish as well.

developit avatar Nov 26 '18 21:11 developit