Skip to content

Commit

Permalink
feat(http-client): improve API for creating new requests
Browse files Browse the repository at this point in the history
This change replaces the `HttpClient.request` getter with an `HttpClient.createRequest()` method to clarify the API for creating new HTTP requests.

Fixes aurelia#27
  • Loading branch information
bryanrsmith committed Mar 21, 2015
1 parent 7cb8cfe commit 67239a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions src/http-client.js
Expand Up @@ -36,16 +36,6 @@ export class HttpClient {
this.isRequesting = false;
}

/**
* Returns a new RequestBuilder for this HttpClient instance which can be used to build and send HTTP requests.
*
* @property request
* @type RequestBuilder
*/
get request(){
return new RequestBuilder(this);
}

/**
* Configure this HttpClient with default settings to be used by all requests.
*
Expand All @@ -60,6 +50,16 @@ export class HttpClient {
return this;
}

/**
* Returns a new RequestBuilder for this HttpClient instance that can be used to build and send HTTP requests.
*
* @method createRequest
* @type RequestBuilder
*/
createRequest(){
return new RequestBuilder(this);
}

/**
* Sends a message using the underlying networking stack.
*
Expand Down Expand Up @@ -108,7 +108,7 @@ export class HttpClient {
* @return {Promise} A cancellable promise object.
*/
delete(uri){
return this.request.delete(uri);
return this.createRequest().delete(uri);
}

/**
Expand All @@ -119,7 +119,7 @@ export class HttpClient {
* @return {Promise} A cancellable promise object.
*/
get(uri){
return this.request.get(uri);
return this.createRequest().get(uri);
}

/**
Expand All @@ -130,7 +130,7 @@ export class HttpClient {
* @return {Promise} A cancellable promise object.
*/
head(uri){
return this.request.head(uri);
return this.createRequest().head(uri);
}

/**
Expand All @@ -142,7 +142,7 @@ export class HttpClient {
* @return {Promise} A cancellable promise object.
*/
jsonp(uri, callbackParameterName='jsoncallback'){
return this.request.jsonp(uri, callbackParameterName);
return this.createRequest().jsonp(uri, callbackParameterName);
}

/**
Expand All @@ -153,7 +153,7 @@ export class HttpClient {
* @return {Promise} A cancellable promise object.
*/
options(uri){
return this.request.options(uri);
return this.createRequest().options(uri);
}

/**
Expand All @@ -165,7 +165,7 @@ export class HttpClient {
* @return {Promise} A cancellable promise object.
*/
put(uri, content){
return this.request.put(uri, content);
return this.createRequest().put(uri, content);
}

/**
Expand All @@ -177,7 +177,7 @@ export class HttpClient {
* @return {Promise} A cancellable promise object.
*/
patch(uri, content){
return this.request.patch(uri, content);
return this.createRequest().patch(uri, content);
}

/**
Expand All @@ -189,6 +189,6 @@ export class HttpClient {
* @return {Promise} A cancellable promise object.
*/
post(uri, content){
return this.request.post(uri, content);
return this.createRequest().post(uri, content);
}
}
8 changes: 4 additions & 4 deletions test/http-client.spec.js
Expand Up @@ -125,7 +125,7 @@ describe('http client', () => {
x.withHeader('Content-Type', 'application/json');
});

client.request
client.createRequest()
.withReplacer(['firstName'])
.put('some/cool/path', content);

Expand Down Expand Up @@ -229,7 +229,7 @@ describe('http client', () => {
x.withHeader('Content-Type', 'application/json');
});

client.request
client.createRequest()
.withReplacer(['firstName'])
.patch('some/cool/path', content);

Expand Down Expand Up @@ -333,7 +333,7 @@ describe('http client', () => {
x.withHeader('Content-Type', 'application/json');
});

client.request
client.createRequest()
.withReplacer(['firstName'])
.post('some/cool/path', content);

Expand Down Expand Up @@ -562,7 +562,7 @@ describe('http client', () => {
var client = new HttpClient();
var callback = function(){};

client.request
client.createRequest()
.withProgressCallback(callback)
.get('some/cool/url');

Expand Down

0 comments on commit 67239a1

Please sign in to comment.