1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import axios from "axios"
class ExternalRESTClients {
constructor() {
if (ExternalRESTClients._instance) {
return ExternalRESTClients._instance
}
ExternalRESTClients._instance = this;
this.doiBaseURL = 'https://dx.doi.org/';
this.headers = {
'Accept': 'application/x-bibtex',
};
this.pmidBaseURL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&retmode=json&id=";
this.tessBaseURL = "https://tess.elixir-europe.org/materials.json?q=";
this.orcidBaseURL = "https://pub.orcid.org/v2.0/";
this.rorOrganisationsBaseURL = "https://api.ror.org/v2/organizations?query=";
}
async getDOI(doi){
let localHeaders = this.headers;
localHeaders['Accept'] = 'application/json';
const request = {
url: this.doiBaseURL + doi,
headers: localHeaders
};
let response = await this.executeQuery(request);
return response.data;
}
async getPMID(id){
const request = {
url: this.pmidBaseURL + id,
headers: {
'Accept': 'application/json',
}
};
let response = await this.executeQuery(request);
return response.data;
}
async getTessRecords(string){
const request = {
url: this.tessBaseURL + string,
headers: this.headers
};
let response = await this.executeQuery(request);
return response.data;
}
async getOrcidUser(user){
this.headers['Accept'] = "application/orcid+json";
const request = {
url: this.orcidBaseURL + user,
headers: this.headers
};
let response = await this.executeQuery(request);
this.headers['Accept'] = 'application/x-bibtex';
return response.data;
}
async getROROrganisation(organisation){
let localHeaders = this.headers;
localHeaders['Accept'] = 'application/json';
const request = {
url: this.rorOrganisationsBaseURL + organisation,
headers: localHeaders
};
let response = await this.executeQuery(request);
return response.data;
}
async executeQuery(query) {
try {
return await axios.get(query.url, {headers: query.headers});
}
catch(e){
return({data: {error: e}});
}
}
}
export default ExternalRESTClients;