DEV Community

Cover image for RESTful API design with Node.js

RESTful API design with Node.js

Adnan Rahić on April 07, 2017

This article was first published on Medium. You can take a look at it here It’s a remarkable beast of a tool, Node.js. If you’re a beginner, aspir...
Collapse
 
viki53 profile image
Corentin H. ⚡

This is great for beginners, but if you want to create a more robust API, you might as well use a framework. Especially if you're considering using Angular as a front-end.

I've used (and contributed to) LoopBack (2 and 3) for a while and it's pretty solid (and built on top of Express by the same guys who created it, so quite a bonus). Plus it manages users and permissions out of the box and there are tools to generate services (and models) for Angular. 😉

I did try Sails a while ago but it didn't go so well, as it was lacking compared to LoopBack.

Collapse
 
adnanrahic profile image
Adnan Rahić

I'd strongly disagree. I've been on the receiving end of a horrible relationship with Sails myself. Never would I want to advise someone to go down that path. Express is incredibly easy to work with, and very flexible. It's already a full-fledged framework. Any more abstraction above it is just overhead, mainly for performance and the cleanliness of your code. Integrating users, permissions and policies is much easier than it sounds. :)

This is just my humble opinion. But, I haven't tried LoopBack yet. Maybe after I do, I'll change my standpoint.

I'm glad you liked the tutorial. Cheers man! :)

Collapse
 
viki53 profile image
Corentin H. ⚡

I haven't explored Sails enough to know what you're talking about but it might be possible form what I remember. :)

LoopBack does bring a few things that you'd have to manage yourself with Express + Mongoose, like sending the right error codes to the client, modular type checking and multiple datasources (files, MongoDB, MySQL, etc.).

There's actually not that much overhead compared to Express (though it might seem like it at first), and it comes from the same team so it's pretty well integrated and you can still use Express if you need it.

Mongoose is also very strict sometimes and that can lead to some headaches. For APIs, it might sometimes be easier to have a more permissive checking (LoopBack has different settings, so you can adjust that).

Anyway, just sharing a tool, not trying to force anyone to convert to any religion. 🙏

Collapse
 
whatsdonisdon profile image
Don Pinkus

Thanks Adnan!

If you have time, would love a writeup that shows how a more complex data model would be handled.

Seeing the canonical Blog use-case of "user", "post", "comment", "tag" would be extremely helpful, and would be the next step for pretty much everyone reading this post :)

Collapse
 
adnanrahic profile image
Adnan Rahić

You're welcome! That's a great idea actually. I've been trying to figure out some cool way of building out on this topic for more experienced readers. This might be it. :)

Collapse
 
chall3ng3r profile image
Faisal Iqbal

Trying out node.js for the 2nd time, good simple to follow guide. I made this simple app with VS2017, and it worked as I followed the guide. Thanks.

Now it'd be awesome if there's similar one for making the UI for this app using bootstrap or other framework.

Collapse
 
adnanrahic profile image
Adnan Rahić

I'm actually in the process of writing one using Angular. Stay tuned. :)

Collapse
 
toomaime profile image
Tobias Hikari

Great article! More of that, please :-)

Collapse
 
adnanrahic profile image
Adnan Rahić

Thank you! I'm glad you liked it. Feel free to check out my latest articles. Many of them continue with similar Node.js topics.

Collapse
 
kavyarani7 profile image
kavyarani7

Detailed to explanation. Good job

Collapse
 
adnanrahic profile image
Adnan Rahić

Thanks! I'm glad you liked it.

Collapse
 
bnhn profile image
Rayy Benhin

This probably is the simplest getting started tutorial on REST I have come across

Collapse
 
adnanrahic profile image
Adnan Rahić

Awesome feedback! Thanks a lot. I'm thrilled you found it useful.

Collapse
 
fasil profile image
fasil

Great article, thanks

Collapse
 
raulruiz profile image
raul-ruiz

Thanks Adnan, great explanation. I have checked several tutorials dealing with this topic, and honestly, this is the best one I have read. Good job! Hope to read more from you soon

Collapse
 
adnanrahic profile image
Adnan Rahić

Thank you! Your kind words mean a lot to me. I'm just happy my writing is actually helping people.