Skip to content

dandeveloper/hello-store-api

Repository files navigation

Profite API

Build Status

Api básica utilizada para estudos.

  • Ruby version: 2.3.3

  • Rails version: 5.0.1

API

Endpoints

Category

Product

Schemas

{"entity": {
    "attribute1": "value",
    "attribute2": "value",
  }
}

OR

{
  "attribute1": "value",
  "attribute2": "value",
}

Examples

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
}

JavaScript Examples XHR

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);

Attributes

Category

string "name"
text "description"
datetime "created_at", null: false (It's an automatic field.)
datetime "updated_at", null: false (It's an automatic field.)

Product

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"

About

A Simple Product Store API. Still in development.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published