Header menu logo fable-electron-docs-api

ClientRequest Type

⚠ Process Availability: Main ✔ | Renderer ❌ | Utility ✔ | Exported ❌

Make HTTP/HTTPS requests.Process: Main, Utility _This class is not exported from the 'electron' module. It is only available as a return value of other methods in the Electron API._ClientRequest implements the Writable Stream interface and is therefore an EventEmitter.

Constructors

Constructor Description

ClientRequest(options)

Full Usage: ClientRequest(options)

Parameters:
    options : U2<Options, string> - If options is a string, it is interpreted as the request URL. If it is an object, it is expected to fully specify an HTTP request via the following properties:

Returns: ClientRequest
options : U2<Options, string>

If options is a string, it is interpreted as the request URL. If it is an object, it is expected to fully specify an HTTP request via the following properties:

Returns: ClientRequest

Instance members

Instance member Description

this.``end``

Full Usage: this.``end``

Parameters:
    ?chunk : U2<string, Buffer>
    ?encoding : string
    ?callback : unit -> unit

Returns: ClientRequest
Modifiers: inline

Sends the last chunk of the request data. Subsequent write or end operations will not be allowed. The finish event is emitted just after the end operation.

?chunk : U2<string, Buffer>
?encoding : string
?callback : unit -> unit
Returns: ClientRequest

this.abort ()

Full Usage: this.abort ()

Modifiers: inline

Cancels an ongoing HTTP transaction. If the request has already emitted the close event, the abort operation will have no effect. Otherwise an ongoing event will emit abort and close events. Additionally, if there is an ongoing response object,it will emit the aborted event.

this.chunkedEncoding

Full Usage: this.chunkedEncoding

A boolean specifying whether the request will use HTTP chunked transfer encoding or not. Defaults to false. The property is readable and writable, however it can be set only before the first write operation as the HTTP headers are not yet put on the wire. Trying to set the chunkedEncoding property after the first write will throw an error.Using chunked encoding is strongly recommended if you need to send a large request body as data will be streamed in small chunks instead of being internally buffered inside Electron process memory.

this.followRedirect ()

Full Usage: this.followRedirect ()

Modifiers: inline

Continues any pending redirection. Can only be called during a 'redirect' event.

this.getHeader name

Full Usage: this.getHeader name

Parameters:
    name : string

Returns: string
Modifiers: inline

The value of a previously set extra header name.

name : string
Returns: string

this.getUploadProgress ()

Full Usage: this.getUploadProgress ()

Returns: GetUploadProgress
Modifiers: inline

  • active boolean - Whether the request is currently active. If this is false no other properties will be set* started boolean - Whether the upload has started. If this is false both current and total will be set to 0.* current Integer - The number of bytes that have been uploaded so far* total Integer - The number of bytes that will be uploaded this requestYou can use this method in conjunction with POST requests to get the progress of a file upload or other data transfer.

Returns: GetUploadProgress

this.offAbort handler

Full Usage: this.offAbort handler

Parameters:
    handler : unit -> unit

Modifiers: inline

Emitted when the request is aborted. The abort event will not be fired if the request is already closed.

handler : unit -> unit

this.offClose handler

Full Usage: this.offClose handler

Parameters:
    handler : unit -> unit

Modifiers: inline

Emitted as the last event in the HTTP request-response transaction. The close event indicates that no more events will be emitted on either the request or response objects.

handler : unit -> unit

this.offError handler

Full Usage: this.offError handler

Parameters:
    handler : Error -> unit

Modifiers: inline

Emitted when the net module fails to issue a network request. Typically when the request object emits an error event, a close event will subsequently follow and no response object will be provided.

handler : Error -> unit

this.offFinish handler

Full Usage: this.offFinish handler

Parameters:
    handler : unit -> unit

Modifiers: inline

Emitted just after the last chunk of the request's data has been written into the request object.

handler : unit -> unit

this.offLogin handler

Full Usage: this.offLogin handler

Parameters:
Modifiers: inline

Emitted when an authenticating proxy is asking for user credentials.The callback function is expected to be called back with user credentials:* username string* password stringProviding empty credentials will cancel the request and report an authentication error on the response object:

handler : IOnLogin -> unit

this.offLogin handler

Full Usage: this.offLogin handler

Parameters:
Modifiers: inline

Emitted when an authenticating proxy is asking for user credentials.The callback function is expected to be called back with user credentials:* username string* password stringProviding empty credentials will cancel the request and report an authentication error on the response object:

handler : AuthInfo -> Option<string> * Option<string> -> unit -> unit

this.offRedirect handler

Full Usage: this.offRedirect handler

Parameters:
Modifiers: inline

Emitted when the server returns a redirect response (e.g. 301 Moved Permanently). Calling request.followRedirect will continue with the redirection. If this event is handled, request.followRedirect must be called synchronously, otherwise the request will be cancelled.

handler : IOnRedirect -> unit

this.offRedirect handler

Full Usage: this.offRedirect handler

Parameters:
    handler : int -> string -> string -> Record<string, string[]> -> unit

Modifiers: inline

Emitted when the server returns a redirect response (e.g. 301 Moved Permanently). Calling request.followRedirect will continue with the redirection. If this event is handled, request.followRedirect must be called synchronously, otherwise the request will be cancelled.

handler : int -> string -> string -> Record<string, string[]> -> unit

this.offResponse handler

Full Usage: this.offResponse handler

Parameters:
Modifiers: inline
handler : IncomingMessage -> unit

this.onAbort handler

Full Usage: this.onAbort handler

Parameters:
    handler : unit -> unit

Modifiers: inline

Emitted when the request is aborted. The abort event will not be fired if the request is already closed.

handler : unit -> unit

this.onClose handler

Full Usage: this.onClose handler

Parameters:
    handler : unit -> unit

Modifiers: inline

Emitted as the last event in the HTTP request-response transaction. The close event indicates that no more events will be emitted on either the request or response objects.

handler : unit -> unit

this.onError handler

Full Usage: this.onError handler

Parameters:
    handler : Error -> unit

Modifiers: inline

Emitted when the net module fails to issue a network request. Typically when the request object emits an error event, a close event will subsequently follow and no response object will be provided.

handler : Error -> unit

this.onFinish handler

Full Usage: this.onFinish handler

Parameters:
    handler : unit -> unit

Modifiers: inline

Emitted just after the last chunk of the request's data has been written into the request object.

handler : unit -> unit

this.onLogin handler

Full Usage: this.onLogin handler

Parameters:
Modifiers: inline

Emitted when an authenticating proxy is asking for user credentials.The callback function is expected to be called back with user credentials:* username string* password stringProviding empty credentials will cancel the request and report an authentication error on the response object:

handler : IOnLogin -> unit

this.onLogin handler

Full Usage: this.onLogin handler

Parameters:
Modifiers: inline

Emitted when an authenticating proxy is asking for user credentials.The callback function is expected to be called back with user credentials:* username string* password stringProviding empty credentials will cancel the request and report an authentication error on the response object:

handler : AuthInfo -> Option<string> * Option<string> -> unit -> unit

this.onRedirect handler

Full Usage: this.onRedirect handler

Parameters:
Modifiers: inline

Emitted when the server returns a redirect response (e.g. 301 Moved Permanently). Calling request.followRedirect will continue with the redirection. If this event is handled, request.followRedirect must be called synchronously, otherwise the request will be cancelled.

handler : IOnRedirect -> unit

this.onRedirect handler

Full Usage: this.onRedirect handler

Parameters:
    handler : int -> string -> string -> Record<string, string[]> -> unit

Modifiers: inline

Emitted when the server returns a redirect response (e.g. 301 Moved Permanently). Calling request.followRedirect will continue with the redirection. If this event is handled, request.followRedirect must be called synchronously, otherwise the request will be cancelled.

handler : int -> string -> string -> Record<string, string[]> -> unit

this.onResponse handler

Full Usage: this.onResponse handler

Parameters:
Modifiers: inline
handler : IncomingMessage -> unit

this.onceAbort handler

Full Usage: this.onceAbort handler

Parameters:
    handler : unit -> unit

Modifiers: inline

Emitted when the request is aborted. The abort event will not be fired if the request is already closed.

handler : unit -> unit

this.onceClose handler

Full Usage: this.onceClose handler

Parameters:
    handler : unit -> unit

Modifiers: inline

Emitted as the last event in the HTTP request-response transaction. The close event indicates that no more events will be emitted on either the request or response objects.

handler : unit -> unit

this.onceError handler

Full Usage: this.onceError handler

Parameters:
    handler : Error -> unit

Modifiers: inline

Emitted when the net module fails to issue a network request. Typically when the request object emits an error event, a close event will subsequently follow and no response object will be provided.

handler : Error -> unit

this.onceFinish handler

Full Usage: this.onceFinish handler

Parameters:
    handler : unit -> unit

Modifiers: inline

Emitted just after the last chunk of the request's data has been written into the request object.

handler : unit -> unit

this.onceLogin handler

Full Usage: this.onceLogin handler

Parameters:
Modifiers: inline

Emitted when an authenticating proxy is asking for user credentials.The callback function is expected to be called back with user credentials:* username string* password stringProviding empty credentials will cancel the request and report an authentication error on the response object:

handler : IOnLogin -> unit

this.onceLogin handler

Full Usage: this.onceLogin handler

Parameters:
Modifiers: inline

Emitted when an authenticating proxy is asking for user credentials.The callback function is expected to be called back with user credentials:* username string* password stringProviding empty credentials will cancel the request and report an authentication error on the response object:

handler : AuthInfo -> Option<string> * Option<string> -> unit -> unit

this.onceRedirect handler

Full Usage: this.onceRedirect handler

Parameters:
Modifiers: inline

Emitted when the server returns a redirect response (e.g. 301 Moved Permanently). Calling request.followRedirect will continue with the redirection. If this event is handled, request.followRedirect must be called synchronously, otherwise the request will be cancelled.

handler : IOnRedirect -> unit

this.onceRedirect handler

Full Usage: this.onceRedirect handler

Parameters:
    handler : int -> string -> string -> Record<string, string[]> -> unit

Modifiers: inline

Emitted when the server returns a redirect response (e.g. 301 Moved Permanently). Calling request.followRedirect will continue with the redirection. If this event is handled, request.followRedirect must be called synchronously, otherwise the request will be cancelled.

handler : int -> string -> string -> Record<string, string[]> -> unit

this.onceResponse handler

Full Usage: this.onceResponse handler

Parameters:
Modifiers: inline
handler : IncomingMessage -> unit

this.removeHeader name

Full Usage: this.removeHeader name

Parameters:
    name : string

Modifiers: inline

Removes a previously set extra header name. This method can be called only before first write. Trying to call it after the first write will throw an error.

name : string

this.setHeader (name, value)

Full Usage: this.setHeader (name, value)

Parameters:
    name : string
    value : string

Modifiers: inline

Adds an extra HTTP header. The header name will be issued as-is without lowercasing. It can be called only before first write. Calling this method after the first write will throw an error. If the passed value is not a string, its toString() method will be called to obtain the final value.Certain headers are restricted from being set by apps. These headers are listed below. More information on restricted headers can be found in Chromium's header utils.* Content-Length* Host* Trailer or Te* Upgrade* Cookie2* Keep-Alive* Transfer-EncodingAdditionally, setting the Connection header to the value upgrade is also disallowed.

name : string
value : string

this.write (chunk, ?encoding, ?callback)

Full Usage: this.write (chunk, ?encoding, ?callback)

Parameters:
    chunk : U2<string, Buffer>
    ?encoding : string
    ?callback : unit -> unit

Modifiers: inline

callback is essentially a dummy function introduced in the purpose of keeping similarity with the Node.js API. It is called asynchronously in the next tick after chunk content have been delivered to the Chromium networking layer. Contrary to the Node.js implementation, it is not guaranteed that chunk content have been flushed on the wire before callback is called.Adds a chunk of data to the request body. The first write operation may cause the request headers to be issued on the wire. After the first write operation, it is not allowed to add or remove a custom header.

chunk : U2<string, Buffer>
?encoding : string
?callback : unit -> unit

Type something to start searching.