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"
});
Content-Type
在响应中,Content-Type标头告诉客户端实际返回的内容的内容类型。
浏览器会在某些情况下进行MIME嗅探,并不一定遵循此标题的值;
为了防止这种行为,可以将标题 X-Content-Type-Options 设置为 nosniff。
在请求中 (如POST 或 PUT),客户端告诉服务器实际发送的数据类型。
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Type
Access-Control-Request-Headers
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Request-Headers
Access-Control-Request-Method
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Request-Method
Response.headers
https://developer.mozilla.org/zh-CN/docs/Web/API/Response/headers
Headers
出于安全考虑,某些头只能由用户代理控制。这些头信息包括 forbidden header names 和 forbidden response header names。
https://developer.mozilla.org/zh-CN/docs/Web/API/Headers
Response/headers
https://developer.mozilla.org/zh-CN/docs/Web/API/Response/headers