Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/http helpers #25

Merged
merged 9 commits into from
Aug 16, 2016
Merged

Feature/http helpers #25

merged 9 commits into from
Aug 16, 2016

Conversation

emoralesb05
Copy link
Contributor

@emoralesb05 emoralesb05 commented Jul 23, 2016

Description

Http helper module, including interceptor wrapper.
#19

What's included?

  • Extracted RESTService from core and added it to http module
  • Added HttpInterceptorService as a http service wrapper to include interceptors into the request pipeline.
  • Added docs for http module.

HttpInterceptorService

Service provided with methods that wrap the ng2 [Http] service and provide an easier experience for interceptor implementation.

To add a desired interceptor, it needs to implement the [IHttpInterceptor] interface.

export interface IHttpInterceptor {
  onRequest?: (requestOptions: RequestOptionsArgs) => RequestOptionsArgs;
  onResponse?: (response: Response) => Response;
  onResponseError?: (error: Response) => Response;
}

Every method is optional, so you can just implement the ones that are needed.

Example for usage:

import { Injectable } from '@angular/core';
import { IHttpInterceptor } from '@covalent/http';

@Injectable()
export class CustomInterceptor implements IHttpInterceptor {

  onRequest(requestOptions: RequestOptionsArgs): RequestOptionsArgs {
    ... // do something to requestOptions
    return requestOptions;
  }

  onResponse(response: Response): Response {
    ... // check response status and do something
    return response;
  }

  onResponseError(error: Response): Response {
    ... // check error status and do something
    return error;
  }
}

Also, you need to bootstrap the interceptor providers

import { HTTP_PROVIDERS } from '@angular/http';
import { provideInterceptors } from '@covalent/http';
import { CustomInterceptor } from 'dir/to/interceptor';

bootstrap(AppComponent, [
  HTTP_PROVIDERS,
  provideInterceptors([CustomInterceptor]),
]);

After that, just inject [HttpInterceptorService] and use it for your requests.

Properties:
image

Test Steps

  • ng serve
  • go to components -> http
  • see docs and how its used.

Screenshots

image

@emoralesb05 emoralesb05 added this to the Alpha 0.6 milestone Jul 23, 2016
@Injectable()
export class CustomRESTService extends RESTService<any> {

constructor(private _http: Http) { // or constructor(private _http: HttpInterceptorService) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this suppose to be commented? i think what you have is valid but maybe having it on its own line would be more clear:

constructor(private _http: Http) { 
/* or constructor(private _http: HttpInterceptorService) { */

or

constructor(private _http: Http) { 
/// or constructor(private _http: HttpInterceptorService) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is intentional I think there should be a note explaining the use cases or just pick one.

On a side note, is an inline comment any better?

constructor(private _http: HTTP /* or HttpInterceptorService */) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe just having it inline works fine, ill change it. 👍 and add a note.

@kyleledbetter kyleledbetter merged commit 2093930 into develop Aug 16, 2016
@emoralesb05 emoralesb05 deleted the feature/http-helpers branch August 16, 2016 23:46
@emoralesb05 emoralesb05 mentioned this pull request Aug 16, 2016
emoralesb05 pushed a commit that referenced this pull request Jul 25, 2019
* added docs content, routing and initial examples

* cleaned up unused class props

* fixed anguler.json test styles references

* removed unused css overide for mininav

* moved theme-dark css under one theme-dark block

* removed unused npath and data/scatter.ts

* feat(): remove icon property frmo interface since it doesnt belong in echarts

also removed unused imports, styles and commented code

* chore(): upgrade Covalent & Angular to get sidenav containerAutosize

* feat(mininav): streamline mininav
kriswinbush pushed a commit to kriswinbush/covalent that referenced this pull request Feb 20, 2020
* added docs content, routing and initial examples

* cleaned up unused class props

* fixed anguler.json test styles references

* removed unused css overide for mininav

* moved theme-dark css under one theme-dark block

* removed unused npath and data/scatter.ts

* feat(): remove icon property frmo interface since it doesnt belong in echarts

also removed unused imports, styles and commented code

* chore(): upgrade Covalent & Angular to get sidenav containerAutosize

* feat(mininav): streamline mininav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants