1.0.1 • Published 2 years ago

@nixcode/ngx-rest v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

ngx-rest

codecov

Install

npm install @nixcode/ngx-rest

Usage

import { ApiClient, Get, JsonRequest } from 'ngx-rest';
import { Injectable } from '@angular/common';

@Injectable({ providedIn: 'root' })
@ApiClient({
    baseUrl: 'https://api.github.com',
    headers: {
      'Content-Type': 'application/json', 
      'Accept': 'application/json'
    }
})
export class GithubService {
    constructor(protected http: HttpClient) { }
    
    @Get('organizations')
    getOrganizations() {
        return new JsonRequest()
            .map(OrganizationsResponse);
    }
}

Extending the service

import { Injectable } from '@angular/common';
import { ApiClient, Get, JsonRequest } from 'ngx-rest';
import { GithubService } from './github.service';

@Injectable({ providedIn: 'root' })
@ApiClient('users')
export class GithubUsersService extends GithubService {
  constructor(http: HttpClient) { super(http); }
  
  @Get(':username')
  getUser(username: string) {
      return new JsonRequest()
          .params({ username })
          .map(UserResponse);
  }
  
  @Get(':username/repos')
  getRepos(username: string) {
      return new JsonRequest()
          .params({ username });
  }
}
1.0.1

2 years ago

1.0.0

2 years ago