DevArt EichJS HTTP Request

From DevArt Knowledgebase
Revision as of 06:19, 19 September 2025 by Daadmin (talk | contribs) (Created page with "HTTP Request is a comprehensive library that allows you to communicate with web services effectively using Vanilla JavaScript. == Info == * Developer: [https://www.devartsoftware.com DevArt Software Co.] * Contributors: Pathum Bandara Premaratne * Latest Version: v1.2 @2021-08-21 * URL: https://js.devartsoftware.com/devart/httprequest/v1.2/devart.httprequest.min.js == Classes == === HttpHeader === HTTP Header Class - Use to send request headers to web services. ====...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

HTTP Request is a comprehensive library that allows you to communicate with web services effectively using Vanilla JavaScript.

Info

Classes

HttpHeader

HTTP Header Class - Use to send request headers to web services.

Constructor

@params
{String} Name
{String} Value

HttpRequest

HTTP Request Class - Use to send requests to web services.

Constructor

@params
{String} ServiceURL - Base URL of the calling API.
{HttpHeader[]} Headers - Collection of headers to be sent with the request. 
{Function} GlobalFail - Function that executes when an exception is not handled.
{Boolean} Silent - Enables/disables the loader.
{Function} ShowLoaderMethod - Method that shows the loader.
{Function} HideLoaderMethod - Method that closes the loader.

Methods

Get

Send requests using the HTTP GET method.

@param
{String} Operation - service name & query string
{Object} Data - Payload
{Function} SuccessMethod - Method to be executed when the request is completed successfully.
{Function} FailMethod - Method to be executed when an error occurred.
Post

Send requests using the HTTP POST method.

@param
{String} Operation - service name & query string
{Object} Data - Payload
{Function} SuccessMethod - Method to be executed when the request is completed successfully.
{Function} FailMethod - Method to be executed when an error occurred.
Put

Send requests using the HTTP PUT method.

@param
{String} Operation - service name & query string
{Object} Data - Payload
{Function} SuccessMethod - Method to be executed when the request is completed successfully.
{Function} FailMethod - Method to be executed when an error occurred.
Delete

Send requests using the HTTP DELETE method.

@param
{String} Operation - service name & query string
{Object} Data - Payload
{Function} SuccessMethod - Method to be executed when the request is completed successfully.
{Function} FailMethod - Method to be executed when an error occurred.
Upload

Upload files and data using the HTTP POST method.

@param
{String} Operation - service name & query string
{Object[]} Data - Payload objects
{Input[type=file]} - File upload control
{Function} SuccessMethod - Method to be executed when the request is completed successfully.
{Function} FailMethod - Method to be executed when an error occurred.
Download

Downloads files from web resources.

@param
{String} Operation - service name.
{String} Parameter - query string parameters.

Samples

//Init Global Error Method
let HandleError = function(Error) { alert(Error); };

//Instantiate Headers
let _Headers = [new HttpHeader("Header1", "Value1"), new HttpHeader("Header2", "Value2")];
 
//Instantiate Request
let _Request = new HttpRequest("https://api.sample.com", _Headers, HandleError, true, ShowLoader, HideLoader);

//Get
Request.Get("Service1", undefined, HanldeSuccessGet, HandleError);

//Post
Request.Post("Service", { Id : 1, Name : 'DevArt' }, HanldeSuccessPost, HandleError);

//Put
Request.Put("Service/1", { Id : 1, Name : 'DevArt' }, HanldeSuccessPut, HandleError);

//Delete
Request.Delete("Service1", undefined, HanldeSuccessGet, HandleError);