Skip to content

Commit 92c6504

Browse files
author
Mayur Patel
committed
Updated to use Angular 2.0.0-rc.4, Updated usage guide in README.md
1 parent a6b6a12 commit 92c6504

File tree

8 files changed

+56
-53
lines changed

8 files changed

+56
-53
lines changed

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,40 @@ npm install angular2-rest
1212

1313
```ts
1414

15-
import {Request, Response} from 'angular2/http';
16-
import {RESTClient, GET, PUT, POST, DELETE, BaseUrl, Headers, DefaultHeaders, Path, Body, Query} from 'angular2-rest';
17-
15+
import {Request, Response} from '@angular/http';
16+
import {
17+
RESTClient, GET, PUT, POST, DELETE, BaseUrl,
18+
Headers, DefaultHeaders, Path, Body, Query
19+
} from 'angular2-rest';
1820
import {Todo} from './models/Todo';
19-
import {SessionFactory} from './sessionFactory';
2021

2122
@Injectable()
22-
@BaseUrl("http://localhost:3000/api/")
23+
@BaseUrl("http://localhost:3000/api/v1/")
2324
@DefaultHeaders({
2425
'Accept': 'application/json',
2526
'Content-Type': 'application/json'
2627
})
2728
export class TodoRESTClient extends RESTClient {
2829

29-
protected requestInterceptor(req: Request) {
30-
if (SessionFactory.getInstance().isAuthenticated) {
31-
req.headers.append('jwt', SessionFactory.getInstance().credentials.jwt);
32-
}
33-
}
34-
35-
protected requestInterceptor(req: Response) {
36-
// do sg with responses
37-
}
38-
30+
@Produces(MediaType.JSON)
3931
@GET("todo/")
4032
public getTodos( @Query("sort") sort?: string): Observable { return null; };
4133

34+
@Produces(MediaType.JSON)
4235
@GET("todo/{id}")
4336
public getTodoById( @Path("id") id: string): Observable { return null; };
4437

38+
@HEADERS({'Authorization': 'Basic 123QWEASDZXC'})
39+
@Produces(MediaType.JSON)
4540
@POST("todo")
4641
public postTodo( @Body todo: Todo): Observable { return null; };
4742

43+
@HEADERS({'Authorization': 'Basic 123QWEASDZXC'})
44+
@Produces(MediaType.JSON)
4845
@PUT("todo/{id}")
4946
public putTodoById( @Path("id") id: string, @Body todo: Todo): Observable { return null; };
5047

48+
@HEADERS({'Authorization': 'Basic 123QWEASDZXC'})
5149
@DELETE("todo/{id}")
5250
public deleteTodoById( @Path("id") id: string): Observable { return null; };
5351

@@ -67,10 +65,16 @@ export class TodoRESTClient extends RESTClient {
6765
})
6866
export class ToDoCmp {
6967

70-
constructor(todoRESTClient: TodoRESTClient) {
68+
constructor(private todoRESTClient: TodoRESTClient) {
69+
this.sampleUsage()
7170
}
72-
73-
//Use todoRESTClient
71+
72+
//Use todoRESTClient
73+
sampleUsage(){
74+
this.todoRESTClient.getTodos().subscribe(data=>{
75+
console.log(data)
76+
})
77+
}
7478
}
7579
```
7680
## API Docs

angular2-rest.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Http, Request } from "angular2/http";
1+
import { Http, Request } from "@angular/http";
22
import { Observable } from "rxjs/Observable";
33
/**
44
* Angular 2 RESTClient class.

angular2-rest.js

Lines changed: 17 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular2-rest.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular2-rest.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ Table of Contents:
2727
@Body
2828
*/
2929

30-
import {Inject} from "angular2/core";
30+
import {Inject} from "@angular/core";
3131
import {
32-
Http, Headers as AngularHeaders,
33-
Request, RequestOptions, RequestMethod as RequestMethods,
34-
Response,
35-
URLSearchParams
36-
} from "angular2/http";
32+
Http, Headers as AngularHeaders,Request, RequestOptions,
33+
RequestMethod as RequestMethods,Response,URLSearchParams
34+
} from "@angular/http";
3735
import {Observable} from "rxjs/Observable";
36+
import 'rxjs/add/operator/map';
3837

3938
/**
4039
* Angular 2 RESTClient class.

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var gulp = require('gulp'),
66
tsc = require('gulp-tsc'),
77
typescript = require('gulp-typescript'),
88
typedoc = require("gulp-typedoc");
9-
9+
1010
var objectMerge = require('object-merge');
1111

1212
var tsProject = typescript.createProject('./tsconfig.json');

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
},
2727
"homepage": "https://github.com/Paldom/angular2-rest#readme",
2828
"dependencies": {
29-
"angular2": "^2.0.0-beta.7",
30-
"es6-promise": "^3.0.2",
31-
"es6-shim": "^0.33.13",
32-
"reflect-metadata": "^0.1.2",
33-
"rxjs": "^5.0.0-beta.0",
34-
"zone.js": "^0.5.10"
29+
"@angular/core": "2.0.0-rc.4",
30+
"@angular/http": "2.0.0-rc.4",
31+
"es6-promise": "^3.2.1",
32+
"es6-shim": "^0.35.1",
33+
"reflect-metadata": "^0.1.3",
34+
"rxjs": "^5.0.0-beta.10",
35+
"zone.js": "^0.6.12"
3536
},
3637
"devDependencies": {
3738
"gulp": "^3.9.0",

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"module": "commonjs",
4-
"target": "es5",
4+
"target": "es6",
55
"noImplicitAny": false,
66
"outDir": ".",
77
"rootDir": ".",
@@ -14,4 +14,4 @@
1414
"exclude": [
1515
"node_modules"
1616
]
17-
}
17+
}

0 commit comments

Comments
 (0)