Basic Rest in atom package


I am trying to make a simple post request to an API outside of Atom. I have tried using Node’s HTTP, Request, and jQuery but each of them has its own collection of errors and issues. I have yet to be able to make a successful post request. Is there anywhere that has an example of rest in a package?

Cross Package Events
How can you make ajax requests?

You can use the brand new fetch API:

fetch('').then(function(response) {

See also


Is that using Implementations look slightly different.


no. If you follow the @olmokramer’s link, you’ll see it’s an experimental browser feature built right into Firefox, Chrome and Opera so far. One day it may become stable and a standard among browsers. As Atom/Electron is based on chrome you can make use of it without installing any additional library. :wink:

@olmokramer nice hint btw. haven’t heard of the fetch API before you mentioned it. thx!


@nylki when I tried to use fetch directly I got fetch is undefined error.


Atom’s still using a version of Electron (/Chromium) that doesn’t support the new fetch API - it’ll be supported once lands.


Any idea on when it will land? I am blocked by not being able to do a post request with a data object from a package. Using the fetch npm package I’m getting odd errors when using the payload parameter so thats another dead end.


I use the request npm module a lot. I’m curious what problems you had with it.


Doing a post request with a data object gave me a first parameter must be a string error, post without the object went through but didn’t work with my API since it requires an configuration object.


If you are using the simple form of the call then the first param is the URL which must be a string. It seems that you are having trouble with basic usage. The package is very solid.

I’m sure there are a lot of examples to be found in the repo and on the web. There is no reason to give up so easily. At worst you could ask a question on the issues list on the repo.


i am following the implementation, request(url, obj, callback) when I do not put an object in with a payload then the request goes through. With the object it throws the parameter error. I can switch over again and get the exact code I implemented with.


Found out what was missing: json: true,
From the documentation:

body - entity body for PATCH, POST and PUT requests. Must be a Buffer or String, unless json is true. If json is true, then body must be a JSON-serializable object.


That’s exactly what I was going to tell you.

(Just kidding, I didn’t have a clue).

Once you get used to it you should like it. The docs are a bit confusing. They are great for advanced features like streaming but weak on basics.