Skip to content

alirezamirian/angular-transfer-http-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Angular Transfer Http Response

A tiny (1kb gzipped) angular module to seamlessly transfer and reuse server-side http responses in front-end.

Installation

npm i angular-transfer-http-response --save

Usage

Import TransferHttpResponseModule in your main module:

import {TransferHttpResponseModule} from 'angular-transfer-http-response';

@NgModule({
  imports: [TransferHttpResponseModule],
  //...
})
export class AppModule {
}

Also don't forget to import ServerTransferStateModule into your AppServerModule.

If you use different base urls in server and browser, you can provide one or more base url as TRANSFER_RESPONSE_BASE_URLS: in your AppModule:

import {TRANSFER_RESPONSE_BASE_URLS} from 'angular-transfer-http-response';

@NgModule({
  //...
  providers: [{
    provide: TRANSFER_RESPONSE_BASE_URLS,
    useValue: ['/api']
  }],
  //...
})
export class AppModule {
}

And in your AppServerModule:

import {TRANSFER_RESPONSE_BASE_URLS} from 'angular-transfer-http-response';

@NgModule({
  //...
  providers: [{
    provide: TRANSFER_RESPONSE_BASE_URLS,
    useValue: ['https://my.domain/api']
  }],
  //...
})
export class AppServerModule {
}

With this configuration, response of a request to https://my.domain/api/some-path in server, will be reused in front-end as response of the first request to /api/some-path. You can provide more than one base url and they will matched correspondingly.

Read more.

About

An angular module for reusing HTTP requests, when using SSR

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published