• Stars
    star
    248
  • Rank 163,560 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Angular2 HTTP client to consume RESTful services. Built with TypeScript.

angular2-rest

Angular2 HTTP client to consume RESTful services. Built on angular2/http with TypeScript.
Note: this solutions is not production ready, it's in a very basic alpha state. Any ideas or contributions are very welcomed :)

Installation

npm install angular2-rest

Example

import {Request, Response} from 'angular2/http';
import {RESTClient, GET, PUT, POST, DELETE, BaseUrl, Headers, DefaultHeaders, Path, Body, Query} from 'angular2-rest';

import {Todo} from './models/Todo';
import {SessionFactory} from './sessionFactory';

@Injectable()
@BaseUrl("http://localhost:3000/api/")
@DefaultHeaders({
    'Accept': 'application/json',
    'Content-Type': 'application/json'
})
export class TodoRESTClient extends RESTClient {

    protected requestInterceptor(req: Request) {
        if (SessionFactory.getInstance().isAuthenticated) {
            req.headers.append('jwt', SessionFactory.getInstance().credentials.jwt);
        }
    }
    
    protected requestInterceptor(req: Response) {
        // do sg with responses
    }

    @GET("todo/")
    public getTodos( @Query("sort") sort?: string): Observable { return null; };

    @GET("todo/{id}")
    public getTodoById( @Path("id") id: string): Observable { return null; };

    @POST("todo")
    public postTodo( @Body todo: Todo): Observable { return null; };

    @PUT("todo/{id}")
    public putTodoById( @Path("id") id: string, @Body todo: Todo): Observable { return null; };

    @DELETE("todo/{id}")
    public deleteTodoById( @Path("id") id: string): Observable { return null; };

}

Using it in your component

@Component({
  selector: 'to-do',
  viewProviders: [TodoRESTClient],
})
@View({
  templateUrl: 'components/to-do-template.html',
})
export class ToDoCmp {

  constructor(todoRESTClient: TodoRESTClient) {
  }
  
  //Use todoRESTClient   
}

API Docs

RESTClient

Methods:

  • getBaseUrl(): string: returns the base url of RESTClient
  • getDefaultHeaders(): Object: returns the default headers of RESTClient in a key-value pair

Class decorators:

  • @BaseUrl(url: string)
  • @DefaultHeaders(headers: Object)

Method decorators:

  • @GET(url: String)
  • @POST(url: String)
  • @PUT(url: String)
  • @DELETE(url: String)
  • @Headers(headers: Object)

Parameter decorators:

  • @Path(key: string)
  • @Query(key: string)
  • @Header(key: string)
  • @Body

License

MIT

More Repositories

1

UniqueDeviceID

PhoneGap / Cordova unique device id (UUID) plugin for Android, iOS and Windows Phone 8. Remains the same after app uninstall.
Objective-C
169
star
2

SpinnerDialog

PhoneGap waiting dialog plugin with spinner for Android, iOS and Windows Phone 8.
Objective-C
68
star
3

PinDialog

PhoneGap numeric password dialog plugin for Android and iOS. Forked from https://github.com/apache/cordova-plugin-dialogs.git
Java
40
star
4

angular-ionic-requirejs-phonegap-seed

Sample PhoneGap / Cordova application built with Angular and Ionic Framework, uses RequireJS for loading scripts. Example controllers, filters, services, directives and config.
JavaScript
36
star
5

docker-sonarqube-mobile-ci

Dockerized SonarQube for mobile projects - Android (Java, Kotlin), iOS (Swift)
Dockerfile
15
star
6

swagger-multifile-example

Example multifile OpenAPI 3.0 (OAS 3.0) specs for mobile and web applications.
9
star
7

ContactNumberPicker

PhoneGap plugin for native contact picker on Android and iOS. The picker shows only name and phone numbers.
Objective-C
7
star
8

angular-social-login

Angular Social Authentication (for PhoneGap/Cordova)
6
star
9

docker-nginx-letsencrypt-proxy

Quick & easy HTTPS reverse proxy for your docker services.
Shell
6
star
10

Mobile-CI

Jenkins based mobile CI.
4
star
11

Mobile-CI-iOS-Example

Example iOS application for mobile CI.
Swift
2
star
12

cordova-stub

PhoneGap / Cordova stub to run and develop cordova apps in desktop browser.
2
star
13

NumericKeyboard

PhoneGap / Cordova numeric keyboard (keypad) plugin for Android.
Java
2
star
14

docker-firebase-test-lab

Docker for Firebase Test Lab.
Shell
2
star
15

fastlane-plugin-set_sonar_properties

Fastlane plugin to load and edit sonar-project.properties files
Ruby
1
star
16

ETrade-Client

ETrade Client
JavaScript
1
star