Commit 1daa167e authored by Administrator's avatar Administrator
Browse files

api suite

parent 2f77630a
......@@ -5,6 +5,6 @@
<div>
<button type="submit" (click)="listdatasets()" class="btn btn-primary">List datasets</button>
</div>
<p>{{result}}</p>
<p>{{dataresult}}</p>
</form>
......@@ -27,43 +27,26 @@ export class DatasetsComponent implements OnInit {
listdatasets() {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'Application/json'
})
};
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
// remplacer l'url api dataverse avec l'enpoint du smart harvester "datasetslist"
this.result = new Promise((r, e) => {
r(this.http.get("https://data.inra.fr/api/search?q=*&type=dataset", httpOptions ).subscribe(r => console.log(r)));
})
this.result.then(
(res) => {
console.log("res = " + JSON.stringify(res, getCircularReplacer()));
this.dataresult = res;
console.log("this.dataresult = " + JSON.stringify(this.dataresult, getCircularReplacer()));
return this.dataresult;
});
console.log(JSON.stringify(this.dataresult, getCircularReplacer()));
return JSON.stringify(this.dataresult, getCircularReplacer());
var myHeaders = new Headers();
myHeaders.append("Content-Type", "Application/json");
var myInit = { method: 'GET', headers: myHeaders};
var myRequest = new Request('https://data.inra.fr/api/search?q=*&type=dataset',myInit);
fetch(myRequest, myInit)
.then(response => {
response.json()
.then(data => {
this.dataresult = JSON.stringify(data);
return this.dataresult["status"];
// console.log(this.dataresult);
});
});
return null;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment