Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accept POST request from other website to Angular Application

I want to accept post request to my Angular application from other application.

Basically they will send customer id list as a POST payload and I have to process it in my angular application & render GUI.

I tried following app.post method in app.js but It throws error "Cannot do POST"

app.post('/customer', function (req, res) {
    console.log(req.body);
});

It is a bit awkward requirement since Angular is JavaScript framework and It does not accept post request because post request needs to be handled at server side only not at client side.

But Is there any work around like accept post request in Node JS and send to angular application and render UI ? Might be a dumb idea so need some idea or work around at least.

Edit:= More Information

I have Node JS application which is mainly to get live data feed through socket.io.

like image 457
Pushkar Rathod Avatar asked Jun 17 '19 22:06

Pushkar Rathod


People also ask

Can Angular accept POST request?

post() method is an asynchronous method that performs an HTTP post request in Angular applications and returns an Observable. HttpClient. post() has a type parameter similar to the HttpClient. get() request, through which we can specify the expected type of the data from the server.


1 Answers

Well, Angular is Front-end framework. You cannot accept POST request from angualar. But you can achieve this by making use of any server-side service like nodejs or java. You can use nodejs for the same. 1. Create a server-side using express or any other framework in nodejs. 2. Your client then have to POST their cutomer id or other data onto that server. 3. Use a database such as mongodb to store data. 4. Then, atlast you need to get data from your server using GET request. It's simple as that.

Like you said in the end, you got a nodejs app having socket.io, well that's good you can get live data by listening to events emitted by socket.io when your client post data. Then you can show those data in your angular app. This can be accomplished with socket.io-client in angular. But, remember you have to send a GET request to server to fetch data again from database(if you're storing them) everytime you restart the application as angular is only a front-end framework. Hope this helps you. You can comment if you got any question. I'll be happy to help!

like image 144
Satnam112 Avatar answered Oct 26 '22 15:10

Satnam112