UNPKG

ng-http-spring

Version:

A Spring Boot-like HTTP library for Angular with decorators, caching, request queuing, file upload, WebSocket, and GraphQL support

170 lines (124 loc) 3.77 kB
# NgHttpSpring A Spring Boot-like HTTP library for Angular with decorators, caching, request queuing, file upload, WebSocket, and GraphQL support. ## Features - Spring-like HTTP decorators (`@Get`, `@Post`, `@Put`, `@Delete`) - Parameter decorators (`@PathVariable`, `@RequestParam`, `@RequestBody`) - Built-in caching support with configurable cache strategies - Request queueing for offline mode and retry support - File upload utilities with progress tracking - WebSocket support with decorator-based configuration - GraphQL client integration - Interceptor support for authentication, error handling, and logging - TypeScript-first development with full type safety ## Installation ```bash npm install ng-http-spring ``` ## Quick Start 1. Import the module: ```typescript import { NgHttpSpringModule } from 'ng-http-spring'; @NgModule({ imports: [ NgHttpSpringModule ] }) export class AppModule { } ``` 2. Use the decorators in your service: ```typescript @Injectable() export class UserService { @Get('/users/{id}') getUser(@PathVariable('id') id: string): Observable<User> { return; // Method implementation is handled by the decorator } @Post('/users') createUser(@RequestBody() user: User): Observable<User> { return; } } ``` ## Advanced Features ### Caching ```typescript @Get('/users', { cache: { expiryMs: 60000 } }) // Cache for 1 minute getUsers(): Observable<User[]> { return; } ``` ### Request Queuing ```typescript @Post('/users', { queue: true }) // Queue requests when offline createUser(@RequestBody() user: User): Observable<User> { return; } ``` ### File Upload ```typescript @Post('/upload') uploadFile(@RequestBody() file: File): Observable<UploadResult> { return; } ``` ### WebSocket ```typescript @WebSocket('/ws') connect(): Observable<WebSocketMessage> { return; } ``` ### GraphQL ```typescript @Query(` query GetUser($id: ID!) { user(id: $id) { name email } } `) getUser(@Variable('id') id: string): Observable<User> { return; } ``` ## Documentation For detailed documentation, please visit: - [HTTP Decorators](docs/http-decorators.md) - [Cache Service](docs/cache-service.md) - [Request Queue](docs/request-queue.md) - [File Upload](docs/file-upload.md) - [WebSocket](docs/websocket.md) - [GraphQL](docs/graphql.md) ## Contributing We welcome contributions! Please read our [contributing guidelines](CONTRIBUTING.md) to get started. ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. To build the library, run: ```bash ng build ng-http-spring ``` This command will compile your project, and the build artifacts will be placed in the `dist/` directory. ### Publishing the Library Once the project is built, you can publish your library by following these steps: 1. Navigate to the `dist` directory: ```bash cd dist/ng-http-spring ``` 2. Run the `npm publish` command to publish your library to the npm registry: ```bash npm publish ``` ## Running unit tests To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command: ```bash ng test ``` ## Running end-to-end tests For end-to-end (e2e) testing, run: ```bash ng e2e ``` Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs. ## Additional Resources For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.