Nodejs - Is there any module existing similar to request module in nodejs? - node.js

I want to make rest api calls from node server. I have currently request module in my mind.
Would you suggest any other best module for REST calls(get/post) for production practise in nodejs ??
Regards,
Ram

Restify was designed specifically for serving RESTful APIs (instead of serving web pages). And it can call RESTful APIs as well.

Here is a nodeJS module called "Deployd" that will help you in creating REST APIs (get/post) in seconds, its community is very limited though. Its quite powerfull as well.
Simply install deployd, it expects nodeJS and mongoDB to be installed already. Deployd provides PHPMyAdmin like web interface through which you can create your APIs and for fine tuning work on deployd's Event API which gives you control on behavior of individual events like GET/POST/DELETE/PUT/VALIDATE etc

I'm using Sails.js to create Rest API. Very easy to use!
Sails.js automatically generates a RESTful JSON API for your app. That means you don't have to write any backend code to build simple database apps.
Install:
sudo npm -g install sails
Create app:
sails new testProject
Lift server:
cd testProject
sails lift
And you are ready!
Update
Regarding your comment, you don't want to create a REST API, but rather consume an existing one.
I found this node module called Node-rest-client. I haven't tried it myself, but looks like this could be what you are looking for.
Allows connecting to any API REST and get results as js Object.

Related

How can I use react with a custom webserver?

I want to use React for a project I am working on, but I also want to use an API.
How can I do it?
I have tried to Google this and ask different people, but I have not got a response yet, so I thought I would ask here. I want to use express and maybe not use create-react-app (as it takes up a lot of storage).
Working on a custom server doesen't preclude the use of an API.
If you want fetch the API from the express server and inject it directly on react frontend you need to enable server side rendering (useful post) and pass the data collected as a props from the server (check this example).
Rather then you can build your react project (using even create-react-app) and build an express server who return the index.html on call.
Personally I prefer the first one solution.

Use VueJS with sailsjs

How do i use vuejs with sails js. I want to list and create dynamic content using Vue. How do I create route for CRUD operations for objects like posts and comments ? How do i check authorization on every route that the user must be logged in for this route to work. One more thing , how can I test the crud operations using Postman
Thanks
You have two ways of using VueJs in Sails.
The view layer of sails js is built on Vue.js, so you can use the native implementation of Vue.js as described in sails js doc.
Or, you can setup a Vue.js standalone app, and make it dial with you sails.js backend by the way of http requests that can you send with http, axios, ... packages .
In both cases, you're gonna use the entry points that you will define in your routes.js file of sails > config folder which would corresponds to controllers that contains your CRUD requests. That is also the way you have to test your "CRUD" operations with postman, by requesting your entry points.
For authorization, a good practice would be to use the policies of Sails.js :)

How to integrate a Nodejs API with ReactJs app under the same domain

I'm trying to understand how a MERN app fully works, I've been reading about MongoDB, ExpressJs, ReactJs and NodeJs, I also understand how MongoDB, ExpressJs and NodeJs interact and how ReactJs works on its own, my question is simple (I think).
The question:
If I create an API, using Node,Express and Mongo, and I have an APP managed by React, both need a server (via express, I understand), then, how should I run the API and the React app at the same time. Do I need different URLs? should I configure different ports? how should I integrate them?
I really been reading a lot, but almost every tutorial is made locally (and I'm working in a server with Passenger and I can't change the way it starts), just for Node/Express(with pug or else)/Mongo or just React, and I don't understand how to connect the API and React.
Thanks
It depends on several factors: environment (e.g. development, production), and your control over the server. For development, you can have two different URLs and use something like Webpack Dev Server. Normally you would have the module bundler, e.g. Webpack, watching for changes in your React code. However, this can get more complex if you have Server Side Rendering.
For production, normally you would have the bundled file for your client side application already optimized and minified. If you can change your API, you could serve it statically in a new endpoint, for example: /static/bundle.js and request this endpoint from your index.html file, which will be sent by Express.js server when accessing /.
However, because you will probably want to have routes in your React app, your server will need to know how to handle the client app routes (for example app.get('/*', () => ...), and they could collide with your API endpoints. To solve this, you could:
Prefix your API endpoints with a namespace, e.g. /api/v1/...
Place the API in a different URL, port or subdomain. In this case you would indeed need to run these two servers in parallel. With Node.js, there are helpers to make this more convenient, e.g. concurrently.
Pulling out your concerns: API, React, and Integration for MERN app.
I use three approaches
1) Use foreman. With this, you can specify your API and Web Client in the Procfile. I used it here
2) Use a proxy to handle requests that require your API. So in package.json, you specify your API URL(your API must be running)
// package.json
.......
.......
"proxy": "<path to url:[port no if you're developing locally]>"
Check here.
And you can simply add a script to run your API and React concurrently.
3) Set your API and React app in a Docker container. mern-starter is a perfect place to check for this.
Hope this helps!

Caching the response to an external web service in hapi.js

Im building a web app in hapi.js. Im pretty new to hapi.js so may not be following the framework correctly. But here is what I intend to do.
Create a hapi route which will use one of the route params to make a series of web service calls to an external host. These calls need to be done in series.
I am currently using axios to make the calls and chaining them with
.then().then() etc.
I would like to cache these responses to a redis store. I read up on the hapi caching examples of using catbox and hapi "server.methods" feature but not sure how they could be applied to a promise based call chain that I have currently. Is there something wrong with my thinking.
Catbox the caching module used by hapi does not support promises as stated here, maybe open an issue on Github or ask a question on gitter or on Github user forum to see what other users are doing.

node.js require.paths.unshift

I'm trying to use webservice in order to expose a REST service on nodejs.
However there are numerous calls in the module and it's dependencies (journey, resourcer) to the now deprecated 'require.paths' , mainly "require.paths.unshift('...')".
i'm using the latest nodejs version (0.6.7).
A. I would like to get this module to work as a first choice. How can i replace require.paths.unshift without causing any errors?
B. If not i would a recommendation of a different module that would let me expose RESTful services easily using nodejs.

Resources