Skip to content

Instantly share code, notes, and snippets.

@P1xt
Created March 17, 2017 20:06
Show Gist options
  • Select an option

  • Save P1xt/ea899adec122194a334ea82716499d48 to your computer and use it in GitHub Desktop.

Select an option

Save P1xt/ea899adec122194a334ea82716499d48 to your computer and use it in GitHub Desktop.
Setting headers on an Angular 2 http get request
import { Injectable } from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
@Injectable()
export class GetWikipediaService {
constructor(private http: Http) { }
searchWiki = (query) => {
let headers = new Headers();
headers.append('Api-User-Agent', 'Example/1.0');
let apiUrl: string = 'https://en.wikipedia.org/w/api.php?format=json&origin=*&action=query&generator=search&prop=extracts|info&inprop=url&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch='+query;
return this.http
.get(apiUrl, headers)
.map(response => response.json());
}
}
@sebastianmorenoe

Copy link
Copy Markdown

Thank you very much!

@RajaParivesh

Copy link
Copy Markdown

Really helpful. Thanks.

@haythemhammami

Copy link
Copy Markdown

thank you very much that's helped me 👍

ghost commented Jun 7, 2018

Copy link
Copy Markdown

are those key value pairs 'Api-User-Agent', 'Example/1.0' ?

@Dev-Pawar

Dev-Pawar commented Sep 5, 2018

Copy link
Copy Markdown

He thanks, you helped me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment