muhammadyana / rest-api-rails

Create simple Restfull API use Ruby on Rails 5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SIMPLE REST API use Rails 5

Technology

INSTALL DEPENDENCIES

$ bundle install

CREATE DATABASE

$ rake db:create

RUN MIGRATION

$ rake db:migrate

MAKE DUMMY DATA

$ rake db:seed

RUN SERVER

$ rails s

Tes using Postman Create Article

http://localhost:3000/api/vi/articles
choose content type and application/json in Headers

choose Body and type use json

{
	"title": "Article from postman third",
	"body": "Lorem Ipsum asas "
}

If success it will return like json format

{
    "status": "SUCCESS",
    "message": "Saved article",
    "data": {
        "id": 9,
        "title": "Article from postman third",
        "body": "Lorem Ipsum asas ",
        "created_at": "2017-08-09T10:30:38.738Z",
        "updated_at": "2017-08-09T10:30:38.738Z"
    }
}

Show All article

Methode GET

http://localhost:3000/api/v1/articles

and will return json format

{
    "status": "hoho Sukses",
    "message": "Loader article",
    "data": [
        {
            "id": 7,
            "title": "Article from postman",
            "body": "Lorem Ipsum",
            "created_at": "2017-08-09T10:29:50.978Z",
            "updated_at": "2017-08-09T10:29:50.978Z"
        },
        {
            "id": 6,
            "title": "as",
            "body": "as",
            "created_at": "2017-08-09T10:29:06.283Z",
            "updated_at": "2017-08-09T10:29:06.283Z"
        },
        {
            "id": 5,
            "title": "Butter In a Lordly Dish",
            "body": "Accusantium ut modi quis amet.",
            "created_at": "2017-08-09T08:03:07.171Z",
            "updated_at": "2017-08-09T08:03:07.171Z"
        },
        {
            "id": 4,
            "title": "The Golden Apples of the Sun",
            "body": "Occaecati architecto facilis expedita.",
            "created_at": "2017-08-09T08:03:07.170Z",
            "updated_at": "2017-08-09T08:03:07.170Z"
        },
        {
            "id": 3,
            "title": "As I Lay Dying",
            "body": "Necessitatibus sed iusto quis mollitia aspernatur reprehenderit consequatur omnis.",
            "created_at": "2017-08-09T08:03:07.168Z",
            "updated_at": "2017-08-09T08:03:07.168Z"
        },
        {
            "id": 2,
            "title": "I Will Fear No Evil",
            "body": "Voluptates laudantium facilis cumque rerum fuga iusto.",
            "created_at": "2017-08-09T08:03:07.166Z",
            "updated_at": "2017-08-09T08:03:07.166Z"
        },
        {
            "id": 1,
            "title": "The Road Less Traveled",
            "body": "Rerum alias non pariatur perspiciatis quasi odit.",
            "created_at": "2017-08-09T08:03:07.146Z",
            "updated_at": "2017-08-09T08:03:07.146Z"
        }
    ]
}

Show One or custom article

Methode GET

http://localhost:3000/api/v1/articles/article_id
example
http://localhost:3000/api/v1/articles/1

will return json format

{
    "status": "hoho Sukses",
    "message": "Loader article",
    "data": {
        "id": 1,
        "title": "The Road Less Traveled",
        "body": "Rerum alias non pariatur perspiciatis quasi odit.",
        "created_at": "2017-08-09T08:03:07.146Z",
        "updated_at": "2017-08-09T08:03:07.146Z"
    }
}

About

Create simple Restfull API use Ruby on Rails 5


Languages

Language:Ruby 74.7%Language:HTML 17.4%Language:CSS 4.7%Language:JavaScript 2.7%Language:CoffeeScript 0.5%