Skip to content

Instantly share code, notes, and snippets.

@dmcblue
Created February 2, 2019 19:32
Show Gist options
  • Save dmcblue/94bbdc8deebd123293b3fba66b85836c to your computer and use it in GitHub Desktop.
Save dmcblue/94bbdc8deebd123293b3fba66b85836c to your computer and use it in GitHub Desktop.
How to make a DELETE Request in Haxe
package test;
import haxe.Http;
import haxe.Json;
import haxe.io.BytesOutput;
class DeleteRequest {
static function main() {
var url = "http://some.url/endpoint";
var response = DeleteRequest.request(url);
trace(response);
}
static public function request(url:String) {
var req:Http = new Http(url);
var responseBytes = new BytesOutput();
req.onError = function(error:String) {
throw error;
};
// Http#onData() is not called with custom requests like PUT
req.onStatus = function(status:Int) {
// For development, you may not need to set Http#onStatus unless you are watching for specific status codes
trace(status);
};
// Http#request is only for POST and GET
// req.request(true);
req.customRequest( true, responseBytes, "DELETE" );
// 'responseBytes.getBytes()' must be outside the onStatus function and can only be called once
var response = responseBytes.getBytes();
// Deserialize in kind
return Json.parse(response.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment