Class Overview
class Http {
constructor
(_backend: ConnectionBackend, _defaultOptions: RequestOptions)
request
(url: string|Request, options?: RequestOptionsArgs) : Observable<Response>
get
(url: string, options?: RequestOptionsArgs) : Observable<Response>
post
(url: string, body: any, options?: RequestOptionsArgs) : Observable<Response>
put
(url: string, body: any, options?: RequestOptionsArgs) : Observable<Response>
delete
(url: string, options?: RequestOptionsArgs) : Observable<Response>
patch
(url: string, body: any, options?: RequestOptionsArgs) : Observable<Response>
head
(url: string, options?: RequestOptionsArgs) : Observable<Response>
options
(url: string, options?: RequestOptionsArgs) : Observable<Response>
}
Class Description
Performs http requests using XMLHttpRequest
as the default backend.
Http
is available as an injectable class, with methods to perform http requests. Calling
request
returns an Observable
which will emit a single Response
when a
response is received.
Example
Example
The default construct used to perform requests, XMLHttpRequest
, is abstracted as a "Backend" (
XHRBackend
in this case), which could be mocked with dependency injection by replacing
the XHRBackend
provider, as in the following example:
Example
Annotations
@Injectable()
Class Details
request(url: string|Request, options?: RequestOptionsArgs) : Observable<Response>
Performs any type of http request. First argument is required, and can either be a url or
a Request
instance. If the first argument is a url, an optional RequestOptions
object can be provided as the 2nd argument. The options object will be merged with the values
of BaseRequestOptions
before performing the request.
get(url: string, options?: RequestOptionsArgs) : Observable<Response>
Performs a request with get
http method.
post(url: string, body: any, options?: RequestOptionsArgs) : Observable<Response>
Performs a request with post
http method.
put(url: string, body: any, options?: RequestOptionsArgs) : Observable<Response>
Performs a request with put
http method.
delete(url: string, options?: RequestOptionsArgs) : Observable<Response>
Performs a request with delete
http method.
patch(url: string, body: any, options?: RequestOptionsArgs) : Observable<Response>
Performs a request with patch
http method.
head(url: string, options?: RequestOptionsArgs) : Observable<Response>
Performs a request with head
http method.
options(url: string, options?: RequestOptionsArgs) : Observable<Response>
Performs a request with options
http method.
exported from http/index, defined in http/src/http.ts