Giter VIP home page Giter VIP logo

my_api_app's Introduction

Ruby Articles API

This is a Ruby on Rails application providing a RESTful API for creating, updating, and deleting articles. It uses standard REST conventions to allow API consumers to interact with article resources.

Getting Started

To get the application running on your local machine, follow these instructions.

Prerequisites

  • Ruby (Check .ruby-version for the specific version)
  • Rails
  • SQLite3 (or the database of your choice, configured in config/database.yml)

Installation

Clone the repository:

git clone <REPOSITORY_URL>
cd <REPO_NAME>

Install the required gems:

bundle install

Create and migrate the database:

rails db:create
rails db:migrate

Start the Rails server:

rails server

Now, the API should be available at http://localhost:3000/

API Endpoints

The following API endpoints are available:

Articles

  • GET /articles - Returns a list of all articles.
  • GET /articles/:id - Returns a single article specified by the :id parameter.
  • POST /articles - Creates a new article with the provided title and body.
  • PATCH/PUT /articles/:id - Updates the article specified by the :id parameter with the provided title and body.
  • DELETE /articles/:id - Deletes the article specified by the :id parameter.

Request & Response Examples

GET(Index) /articles

Request: curl -X GET http://localhost:3000/articles

Response body (JSON):

[
  {
    "id": 1,
    "title": "First Article",
    "body": "This is the body of the first article",
    "created_at": "2024-01-22T20:14:26.782Z",
    "updated_at": "2024-01-22T20:14:50.054Z"
  },
  {
    "id": 2,
    "title": "Second Article",
    "body": "This is the body of the second article"
    "created_at": "2024-01-22T20:14:26.782Z",
    "updated_at": "2024-01-22T20:14:50.054Z"
  }
]
GET(Show) /articles/:id

Request: curl -X GET http://localhost:3000/articles/1

Response body (JSON):

{
    "id": 1,
    "title": "First Article",
    "body": "This is the body of the first article",
    "created_at": "2024-01-22T20:14:26.782Z",
    "updated_at": "2024-01-22T20:14:50.054Z"
}
POST(Create) /articles

Request: curl -X POST http://localhost:3000/articles -H "Content-Type: application/json" -d '{"title": "New Article", "body": "Article body"}'

Response body (JSON):

{
  "id": 3,
  "title": "New Article",
  "body": "Article body",
  "created_at": "2024-01-24T05:35:38.097Z",
  "updated_at": "2024-01-24T05:35:38.097Z"
}
POST(Create) /articles/:id

Request: curl -X PUT http://localhost:3000/articles/1 -H "Content-Type: application/json" -d '{"title": "Updated Title", "body": "Updated body"}'

Response body (JSON):

{
  "title": "Updated Title",
  "body": "Updated body",
  "id": 1,
  "created_at": "2024-01-22T20:14:26.782Z",
  "updated_at": "2024-01-22T20:14:50.054Z"
}
DELETE(Destroy) /articles/:id

Request: curl -X DELETE http://localhost:3000/articles/1

Response body (JSON): None

my_api_app's People

Watchers

Aditya Relangi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.