mlab, mongodb, db, json, api, free , online,
https://gist.github.com/xgqfrms-GitHub/636260e8332f0fe4f530fe040ffd3741
fetch('https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest',{
method: 'get',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Api-Key': `0987b00e542141369049e647701b65d9`
}
})
.then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json: ', json)
}).catch(function(error) {
console.log('parsing failed: ', error)
});
// {"id": 2017003, "name": "test", "age": 27}
$.ajax({
url: "https://api.mlab.com/api/1/databases/node-mongodb/collections/test?apiKey=pa4Yku0O7y6CHLqKwDGlLKSfkdPfQprR",
data: JSON.stringify([]),
type: "PUT",
contentType: "application/json"
});
$.ajax({
url: "https://api.mlab.com/api/1/databases/node-mongodb/collections/test?apiKey=pa4Yku0O7y6CHLqKwDGlLKSfkdPfQprR",
type: "DELETE",
accepts: {
contentType: "application/json",
},
async: true,
timeout: 300000,
success: function (data) {
console.log(data);
},
error: function (xhr, status, err) {
console.log(xhr, status, err);
}
});
http://docs.mlab.com/data-api/#delete-documents
Access-Control-Allow-Methods
headers.add("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE");
https://stackoverflow.com/questions/28990565/delete-is-not-allowed-by-access-control-allow-methods
https://api.jquery.com/jQuery.ajax/
$.ajax({
accepts: {
mycustomtype: 'application/x-some-custom-type'
},
// Instructions for how to deserialize a `mycustomtype`
converters: {
'text mycustomtype': function(result) {
// Do Stuff
return newresult;
}
},
// Expect a `mycustomtype` back from server
dataType: 'mycustomtype'
});
http://docs.mlab.com/data-api/#delete-documents
$.ajax({
url: 'https://api.mlab.com/api/1/databases/my-db/collections/my-coll?apiKey=myAPIKey',
data: JSON.stringify([{"x": 1}, {"x": 2}, {"x": 3}]),
type: "PUT",
contentType: "application/json"
});
Specifying an empty list in the body is equivalent to deleting the documents matching the query.
在正文中指定空列表等同于删除与查询匹配的文档。
$.ajax({
url: 'https://api.mlab.com/api/1/databases/my-db/collections/my-coll?apiKey=myAPIKey',
data: JSON.stringify([{"x": 1}, {"x": 2}, {"x": 3}]),
type: "DELETE",
contentType: "application/json"
});
https://github.github.io/fetch/#request-body