Skip to content
This repository was archived by the owner on Jul 18, 2020. It is now read-only.

Repository files navigation

@streamjar/frontend-common

frontend-common is a shared library shared between our frontends (frontend2, usersite2, developers) which aids in execution of HTTP requests and any other shared logic.

For simplicity, this is a new repository. You can find the archived frontend-common (and frontend1 version) here

The core holds all of the logic which gets shared between platforms. Roughly speaking it contains:

  • Models for all of our endpoints
  • Access to metadata for bot commands
  • Textual reasons for point values
  • Documentation on the OAuth scopes we support.

Using modeling requires an instance of HttpService to be passed into the constructor. It's up to the client application to implement this. For instance, in Angular we provide a slim wrapper around their HttpClient (@streamjar/frontend-common-ng).

This is a package designed to aid the use of modeling within Angular's DI. You must provide your own implementation of HttpService which is provided into Angular.

Using @streamjar/frontend-common-ng
import{NgModule}from'@angular/core';import{HttpService}from'@streamjar/frontend-common-core';import{FrontendCommonModule}from'@streamjar/frontend-common-ng';
@NgModule({imports: [
...
FrontendCommonModule,],providers: [{provide: HttpService,useClass: JarService},]})exportclassAppModule{}
Example HttpService
@Injectable()exportclassJarServiceextendsHttpService{constructor(privatehttp: HttpClient){super({endpoint: config.api.url,version: config.api.version,});}publicget<T>(uri: string): Observable<T>{returnthis.http.get<T>(this.buildUrl(uri),{headers: this.getHeaders(uri)});}publicpost<T>(uri: string,body: any): Observable<T>{returnthis.http.post<T>(this.buildUrl(uri),body,{headers: this.getHeaders(uri)});}publicpatch<T>(uri: string,body: any): Observable<T>{returnthis.http.patch<T>(this.buildUrl(uri),body,{headers: this.getHeaders(uri)});}publicput<T>(uri: string,body: any): Observable<T>{returnthis.http.put<T>(this.buildUrl(uri),body,{headers: this.getHeaders(uri)});}publicdelete<T>(uri: string): Observable<T>{returnthis.http.delete<T>(this.buildUrl(uri),{headers: this.getHeaders(uri)});}}

About

This is configured as a mono-repo, using lerna. Publishing should not be done manually.

About

📚Shared library that powers our frontends (frontend2, usersite2, developers and beyond)!

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages