Api básica utilizada para estudos.
-
Ruby version: 2.3.3
-
Rails version: 5.0.1
-
https://profite-study-api.herokuapp.com/api/categories - GET / POST
-
https://profite-study-api.herokuapp.com/api/categories/{:id} - GET / PUT / PATCH
-
https://profite-study-api.herokuapp.com/api/products - GET / POST
-
https://profite-study-api.herokuapp.com/api/products/{:id} - GET / PUT / PATCH
{"entity": {
"attribute1": "value",
"attribute2": "value",
}
}OR
{
"attribute1": "value",
"attribute2": "value",
}Json Format
{"product": {
"name": "Livro Rails 5",
"description": "Livro que ensina o Framework Rails e permite você desenvolver um site do zero ao deploy usando as melhores técnicas de desenvolvimento.",
"short_description": "Livro que ensina o Framework Rails",
"price": 40.00,
"best_price": 29.99,
"quantity": 50
}
}OR
{
"name": "Livro Rails 5",
"description": "Livro que ensina o Framework Rails e permite você desenvolver um site do zero ao deploy usando as melhores técnicas de desenvolvimento.",
"short_description": "Livro que ensina o Framework Rails",
"price": 40.00,
"best_price": 29.99,
"quantity": 50
}GET
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://profite-study-api.herokuapp.com/api/categories", true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.setRequestHeader("Authorization", "Token token=API_TOKEN");
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
console.log(xhr.responseText);
}
}
xhr.send();POST
var data = {
name: "Categoria js",
description: "Essa é uma Terceira Categoria enviada por JS"
};
data = JSON.stringify(data);
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://profite-study-api.herokuapp.com/api/categories/{:id}", true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.setRequestHeader("Authorization", "Token token=API_TOKEN");
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
console.log(xhr.responseText);
}
}
xhr.send(data);PUT
var data = {
name: "Categoria Alterada",
description: "Essa é uma descrição alterada pelo PUT."
};
data = JSON.stringify(data);
var xhr = new XMLHttpRequest();
xhr.open("PUT", "https://profite-study-api.herokuapp.com/api/categories/{:id}", true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.setRequestHeader("Authorization", "Token token=API_TOKEN");
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
console.log(xhr.responseText);
}
}
xhr.send(data);PATCH
var data = {
description: "Essa é uma descrição alterada pelo PATCH."
};
data = JSON.stringify(data);
var xhr = new XMLHttpRequest();
xhr.open("PATCH", "https://profite-study-api.herokuapp.com/api/categories/{:id:}", true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.setRequestHeader("Authorization", "Token token=API_TOKEN");
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
console.log(xhr.responseText);
}
}
xhr.send(data);DELETE
var xhr = new XMLHttpRequest();
xhr.open("DELETE", "https://profite-study-api.herokuapp.com/api/categories/{:id}", true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.setRequestHeader("Authorization", "Token token=API_TOKEN");
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
console.log(xhr.responseText);
}
}
xhr.send(null);string "name"
text "description"
datetime "created_at", null: false (It's an automatic field.)
datetime "updated_at", null: false (It's an automatic field.)
string "name"
text "description"
string "short_description"
decimal "price"
decimal "best_price"
integer "quantity"
datetime "created_at", null: false (It's an automatic field.)
datetime "updated_at", null: false (It's an automatic field.)
integer "category_id"