Skip to content

Instantly share code, notes, and snippets.

@IAfanasovMob
Created October 8, 2019 12:04
Show Gist options
  • Save IAfanasovMob/39f2f719463f8c034182378a52d6c198 to your computer and use it in GitHub Desktop.
Save IAfanasovMob/39f2f719463f8c034182378a52d6c198 to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class GitHubApiVersionInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (req.url.startsWith('https://api.github.com/')) {
const clone = req.clone({
setHeaders: { Accept: 'application/vnd.github.v3.star+json' }
});
return next.handle(clone);
}
return next.handle(req);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment