Here is how I do the request in curl:
curl -v --request PATCH -H "Authorization: token TOKEN-VALUE-FROM-PREVIOUS-CALL" -d '{"description": "updated gist","public": true,"files": {"file1.txt": {"content": "String file contents are now updated"}}}' https://api.github.com/gists/GIST-ID-FORM-PREVIOUS-CALL
I have tried a few node libraries to make that "patch" request but no success. I can also do the same thing in client side with jQuery.ajax but can't get it working on the server side. Thanks in advance.
Using the native HTTP request function in Node.js, you can make your requests as follows -
var qs = require("querystring");
var http = require("https");
var options = {
"method": "PATCH",
"hostname": "api.github.com",
"port": null,
"path": "/gists/GIST-ID-FORM-PREVIOUS-CALL",
"headers": {
"authorization": "token TOKEN-VALUE-FROM-PREVIOUS-CALL",
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(qs.stringify(
{
"description": "updated gist",
"public": "true",
"files": {
"file1.txt": {
"content": "String file contents are now updated"
}
}
}));
req.end();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With