chore(http): assert that url is present when creating new Request

Closes #4650
This commit is contained in:
mgechev 2015-10-10 19:37:29 +03:00 committed by Misko Hevery
parent 1dc8a0a95d
commit ebd15a7855
2 changed files with 9 additions and 4 deletions

View File

@ -23,10 +23,10 @@ export abstract class Connection {
}
/**
* Interface for options to construct a Request, based on
* Interface for options to construct a RequestOptions, based on
* [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
*/
export type RequestOptionsArgs = {
export interface RequestOptionsArgs {
url?: string;
method?: string | RequestMethods;
search?: string | URLSearchParams;
@ -35,6 +35,11 @@ export type RequestOptionsArgs = {
body?: string;
}
/**
* Required structure when constructing new Request();
*/
export interface RequestArgs extends RequestOptionsArgs { url: string; }
/**
* Interface for options to construct a Response, based on
* [ResponseInit](https://fetch.spec.whatwg.org/#responseinit) from the Fetch spec.

View File

@ -1,5 +1,5 @@
import {RequestMethods} from './enums';
import {RequestOptions} from './base_request_options';
import {RequestArgs} from './interfaces';
import {Headers} from './headers';
import {normalizeMethodName} from './http_utils';
import {
@ -61,7 +61,7 @@ export class Request {
url: string;
// TODO: support URLSearchParams | FormData | Blob | ArrayBuffer
private _body: string;
constructor(requestOptions: RequestOptions) {
constructor(requestOptions: RequestArgs) {
// TODO: assert that url is present
let url = requestOptions.url;
this.url = requestOptions.url;