Skip to content

Commit e9b89ca

Browse files
committed
Readme changes
1 parent a86a7c8 commit e9b89ca

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Working demo https://plnkr.co/edit/OgvZ09iYO64VoXHLRGQa?p=preview
1515
- [Examples](#examples)
1616
- [Usage](#usage)
1717
- [Configuration](#configuration)
18+
- [Endpoint Url](#config-endpointurl)
19+
- [Batch Endpoint Url](#config-batchurl)
20+
- [Enabled](#config-enabled)
1821

1922
## <a name="get-started"></a> Get Started
2023

@@ -33,6 +36,7 @@ There isn't much too visually see but you will want to open up the network tab o
3336
### <a name="usage"></a> Usage
3437
`NgxHttpBatcherModule` should be registered in the `AppModule` imports. This module relies on the Angular HttpModule so ensure that is also imported.
3538

39+
The below bit of code is everything you need to get going. However, I'll explain it below.
3640

3741
```javascript
3842
import { BrowserModule } from "@angular/platform-browser";
@@ -50,8 +54,8 @@ import { AppComponent } from "./app.component";
5054
export function httpBatchConfigurationFactory() {
5155
return new HttpBatchConfigurationCollection([
5256
new HttpBatchConfiguration({
53-
rootEndpointUrl: "https://my.service.com",
54-
batchEndpointUrl: "https://my.service.com/$batch"
57+
rootEndpointUrl: "https://api.myservice.com",
58+
batchEndpointUrl: "https://api.myservice.com/$batch"
5559
})]);
5660
};
5761

@@ -76,4 +80,53 @@ export function httpBatchConfigurationFactory() {
7680
export class AppModule { }
7781
```
7882

83+
Then you can just use the Http service as you normally would safe in the knowlegde that requests to you batchable service (configured above) will be batched.
84+
85+
```javascript
86+
import { Component } from "@angular/core";
87+
import { Http } from "@angular/http";
88+
89+
@Component({
90+
selector: "app-root",
91+
templateUrl: "./app.component.html",
92+
styleUrls: ["./app.component.css"]
93+
})
94+
export class AppComponent {
95+
public somedata: string[];
96+
public otherdata: string[];
97+
98+
public constructor(private http: Http) {
99+
http.get("https://api.myservice.com/somedata")
100+
.subscribe(response => this.somedata = response.json());
101+
http.get("https://api.myservice.com/otherdata/123-456")
102+
.subscribe(response => this.otherdata = response.json());
103+
http.put("https://api.myservice.com/jobs", { id: 1, name: "Angular Wizard" })
104+
.subscribe();
105+
}
106+
}
107+
```
108+
109+
110+
### <a name="configuration"></a> Configuration
111+
112+
Below are all the configuration options for a single batch endpoint. Note that you can have as many batch endpoints as you want but you would need a seperate configuraiton object for each one.
113+
114+
### <a name="config-endpointurl"></a> Endpoint Url
115+
The root endpoint url which is used to determine if the http call is destinted to an endpoint that can be batched.
116+
For example you endpoint might be:
117+
118+
```https://api.myservice.com```
119+
120+
Calls to ```https//api.myservice.com/users``` or ```https//api.myservice.com/users/fdfkhdf-3432e23wd/friends?limit=10&from=0``` would be batched.
121+
Calls to ```https://qa.myservice.com/bugs``` would not be batched as the subdomain are different.
122+
123+
### <a name="config-batchurl"></a> Batch Endpoint Url
124+
The url of the exposed batch endpoint that is associated with the service defined in rootEndpointUrl.
125+
126+
For example
127+
128+
```https://api.myservice.com/$batch```
129+
130+
### <a name="config-enabled"></a> Enabled
131+
This optional parameter defaults to true. If false calls that would normally be batched to this endpoint will just be passed through as normal HTTP calls.
79132

0 commit comments

Comments
 (0)