KO
|
EN
gitlite — search
Search
#python
#java
#python3
#arduino
#golang
#machine-learning
#rust
#html
#flask
#javascript
#seismology
#nodejs
ngx-api-resource
★ 10
Open GitHub ↗
No description available.
Download README (.md)
Explore Similar Repositories
flytecopilot
:
The Flyte data-sidecar that helps move the input and output data intelligently between containers
Basic-Banking-Application
:
No description available.
tanzu-spring-cloud-gateway
:
Hello World getting started with Tanzu Spring Cloud Gateway
Deep-Mixed-Reality-IoT-Control-System-HoloLens2
:
RaspberryPi IoT Control System using UDP Socket, which is detected from embedded deep learning model and connected from Python-C# in HoloLens2 with Unity3D
webpack-cloud-functions
:
Webpack integration for cloud/lambda functions
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
ngx-api-resource
?
Download (.md)
# ngx-api-resource ## Getting started ### Installation To install the package from npm - run `npm install ngx-api-resource` ### Setup ```typescript import { NgxApiResourceModule } from 'ngx-api-resource'; @NgModule({ imports: [ ... NgxApiResourceModule.forRoot({ baseUrl: 'http://l8-api.test/', prefix: '/api' }) ], }) export class AppModule {} ``` ### Usage 1. Define service ```typescript import { NgxApiResourceService } from 'ngx-api-resource'; export interface UserResource { id: number; name: string; email: string; email_verified_at: string; created_at: string; updated_at: string; } @Injectable({ providedIn: 'root' }) export class UserResourceService extends NgxApiResourceService<UserResource> { protected model = 'users'; // prefix url } ``` Default NgxApiResourceService already implement all method bellow: | Verb | URI | Method | Summary | |----------- |--------------- |--------- |-------------------------------- | | GET | /users | index | Fetches the list of resources. | | POST | /users | store | Creates new resources. | | GET | /users/{user} | show | Fetches a resource. | | PUT/PATCH | /users/{user} | update | Updates a resource. | | DELETE | /users/{user} | destroy | Deletes a resource. | To define a custom method ```typescript @Injectable({ providedIn: 'root' }) export class UserResourceService extends NgxApiResourceService<UserResource> { protected model = 'users'; // prefix url approve(userId: string | number): Observable<HttpResponse<any>> { return this.ngxApiClient.post(`/${this.model}/${userId}/approve`); } } ``` 2. Define component and inject service ```typescript import { UserResource, UserResourceService } from './user-resource.service'; import { CollectionResource } from 'ngx-api-resource'; @Component({ selector: 'users', templateUrl: './users.component.html', styleUrls: ['./users.component.scss'] }) export class UsersComponent implements OnInit { constructor(private userResourceService: UserResourceService) {} // Fetches the list of resources. index(): Observable<CollectionResource<UserResource>> { return this.userResourceService.index() } // Creates new resources. store(attributes: any): Observable<UserResource> { return this.userResourceService.store(attributes) } // Fetches a resource. show(id: string|number): Observable<UserResource> { return this.userResourceService.show(id) } // Updates a resource. update(id: string|number, attributes: any): Observable<UserResource> { return this.userResourceService.update(id,attributes) } // Deletes a resource. delete(id: string|number): Observable<HttpResponse<any>> { return this.userResourceService.destroy(id) } // Approve user approve(id: string|number): Observable<HttpResponse<any>> { return this.userResourceService.approve(id) } } ```