O'Reilly logo

Hands-On Microservices with Node.js by Diogo Resende

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactor routes

These options look neat but, following the route we're doing, it will probably be a mess to create all the path possibilities. We're also narrowing on the image names as we're creating virtual prefixes for these image manipulations options.

Let's make a change while we're at the beginning. Instead of using route parameters, let's use query parameters. They can be added in the order we want, and don't affect the path. We could also use request headers, but these would be harder to test both on the browser and using fetching modules such as request.

So, before we add our neat image manipulations, let's refactor our code to use query parameters. Express handles and decodes query parameters automatically, so we just need to change ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required