ng-http-spring
v1.0.0-beta.0
Published
A Spring Boot-like HTTP library for Angular with decorators, caching, request queuing, file upload, WebSocket, and GraphQL support
Maintainers
Readme
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
npm install ng-http-springQuick Start
- Import the module:
import { NgHttpSpringModule } from 'ng-http-spring';
@NgModule({
imports: [
NgHttpSpringModule
]
})
export class AppModule { }- Use the decorators in your service:
@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
@Get('/users', { cache: { expiryMs: 60000 } }) // Cache for 1 minute
getUsers(): Observable<User[]> {
return;
}Request Queuing
@Post('/users', { queue: true }) // Queue requests when offline
createUser(@RequestBody() user: User): Observable<User> {
return;
}File Upload
@Post('/upload')
uploadFile(@RequestBody() file: File): Observable<UploadResult> {
return;
}WebSocket
@WebSocket('/ws')
connect(): Observable<WebSocketMessage> {
return;
}GraphQL
@Query(`
query GetUser($id: ID!) {
user(id: $id) {
name
email
}
}
`)
getUser(@Variable('id') id: string): Observable<User> {
return;
}Documentation
For detailed documentation, please visit:
Contributing
We welcome contributions! Please read our contributing guidelines to get started.
License
This project is licensed under the MIT License - see the LICENSE file for details.
To build the library, run:
ng build ng-http-springThis 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:
Navigate to the
distdirectory:cd dist/ng-http-springRun the
npm publishcommand to publish your library to the npm registry:npm publish
Running unit tests
To execute unit tests with the Karma test runner, use the following command:
ng testRunning end-to-end tests
For end-to-end (e2e) testing, run:
ng e2eAngular 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 page.
