API Post Request



I have some data that i need to POST to the webserver. However I am completely how to do that. Basically I need to send data on button click. What have I tried so far:

  1. Simple post action from the method
  2. Tried to mix with Angular
  3. Tried npm packages request and superagent (couldn’t make them work on click)

Looking for some kind of advice, I am stuck here for a whole day. Thanks :).


If by #1 you’re referring to the method in the Node HTTP module for making requests, then that should be the way to do it. Have you had somebody look at your code to see what’s going wrong?


Parod me if I am being an newbie. If I am right the npm request happens on the backend, however I need to make a mixin with frontend, so the request happens only on button click. Request itself works fine when it is not mixed with button “onclick”.


I think you think that there’s more of a distinction between frontend and backend in JavaScript than there actually is. The “front” is just everything the user sees, and the “back” is just everything they don’t. All you need is to have a button on some page in your app call a function in a file that has a require("http") statement.

NPM is the package manager for packages in the Node.js ecosystem. If you say “the npm request”, people are going to go looking here to find out what you’re talking about. If you actually mean a built-in Node module, don’t say it’s from NPM.


The more modern way to perform async requests to an API server is via fetch. This is quite new, but it is supported in the node version current Atom is built on, and it is to be preferred.

There are plenty of examples online, but if you want to see an example of it working within Atom, then you can look at the source code of geiger, a package that I maintain myself. More specifically, you should look here.



Thanks for your great answer :).