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

Kieron Taylor ktaylor at ebi.ac.uk
Tue Sep 20 09:24:16 BST 2016


Hi Manu,

We typically recommend two headers: Content-type and accepts. They can differ, but our implementation isn't perfect and messes up content and accepts under certain circumstances.

It is possible that your client library is setting an accept header of its own. Also please note that different endpoints support different content types, such as the Compara endpoints allowing Newick format. Try forcing accepts to application/json and go from there. If you're still having trouble, send us the debug dump of the entire message header.

Regards,


Kieron

> On 19 Sep 2016, at 20:27, Manu Gupta <gmanu at umich.edu> wrote:
> 
> 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
> 
> _______________________________________________
> Dev mailing list    Dev at ensembl.org
> Posting guidelines and subscribe/unsubscribe info: http://lists.ensembl.org/mailman/listinfo/dev
> Ensembl Blog: http://www.ensembl.info/





More information about the Dev mailing list