[ensembl-dev] REST API guidelines for Ensemble when used on Angular2 using observables

Manu Gupta gmanu at umich.edu
Mon Sep 19 20:27:53 BST 2016


Hi everyone,

I have been trying to get the REST API from Ensemble running on
Angular2 using observables. I am not sure what the problem is with it.
This is how my code looks like

Notice that I have added proper headers. To verify, we can change the
header value and see that we receive a 415 if I change the header
name.

-----
    let header = new Headers();
    header.append('Content-type', 'application/json');
    this.http.get('http://rest.ensembl.org/lookup/id/ENSG00000157764?expand=0',
{
      headers: header
    })
      .map((res: Response) => res.json())
      .subscribe(
      data => {
        console.log('data');
        this.data = data;
      },
      error => {
        this.errorMessage = <any>error;
      },
      () => console.log('random look complete'));
-----

I have also tried my API with only the Content-type header set as
application/json on Postman it works without any issue using the same
ID and header.


In order to debug further, I used an alternate API  which works fine

----
       this.http.get('http://jsonplaceholder.typicode.com/photos/1')
        .map((res: Response) => res.json())
            .subscribe(res => {
                this.data = res;
                this.errorMessage = false;
            });
----

Am I missing out on anything from headers?



Cheers,

Manu Gupta




More information about the Dev mailing list