Git Product home page Git Product logo

rails_api_demo's Introduction

Overview

This is a tiny RESTful API to index a page's content. "Index the content" means to parse the page content and store its content - in this case to store the content that is found inside the tags h1, h2 and h3 and the links.

Semaphore CI : Build Status

Project Setup

  • Ruby version - 2.3.1

  • Rails version - 5.0.0

  • Database creation - I have used Sqlite database in this project. Run rails db:setup in console from your project path

  • Test code - I have used rspec to test code. Run rspec to run all test code.

  • Security check - I have used brakeman to check security issues. Run brakeman from project root directory.

  • Syntax check - I have used rubocop to analyze static Ruby code. Run rubocop from project root directory.

API Documentation

Save content of a url :

Request: POST /web_pages with parameter web_page[url]=https://example.com

Response:

{
  "id": 2,
  "url": "https://example.com",
  "content": "[{:tag=>\"h1\", :text=>\"Example Domain\"}]",
  "updated_at": "2016-07-04T20:15:27.312Z"
}

Update previous saved content :

Request: PATCH/PUT /web_pages/2 with parameter web_page[url]=https://example.com

Response:

{
  "id": 2,
  "url": "https://example.com",
  "content": "[{:tag=>\"h1\", :text=>\"Example Domain\"}, {:tag=>\"a\", :text=>\"More information...\"}]",
  "updated_at": "2016-08-04T16:36:19.335Z"
}

Get all saved contents :

Request: GET /web_pages with no parameter

Response:

[
  {
    "id": 1,
    "url": "https://github.com/tauhidul35/rails-api-demo",
    "content": "[{:tag=>\"h1\", :text=>\"tauhidul35/rails-api-demo\"}, {:tag=>\"h1\", :text=>\"README\"}, {:tag=>\"h3\", :text=>\"README.md\"}, {:tag=>\"a\", :text=>\"Skip to content\"}, {:tag=>\"a\", :text=>\"\"}, {:tag=>\"a\", :text=>\"Personal\"}, {:tag=>\"a\", :text=>\"Open source\"}, {:tag=>\"a\", :text=>\"Business\"}, {:tag=>\"a\", :text=>\"Explore\"}, {:tag=>\"a\", :text=>\"Sign up\"}, {:tag=>\"a\", :text=>\"Sign in\"}, {:tag=>\"a\", :text=>\"Pricing\"}, {:tag=>\"a\", :text=>\"Blog\"}, {:tag=>\"a\", :text=>\"Support\"}, {:tag=>\"a\", :text=>\"Search GitHub\"}, {:tag=>\"a\", :text=>\"Watch\"}]",
    "updated_at": "2016-08-04T16:13:29.169Z"
  },
  {
    "id": 2,
    "url": "https://example.com",
    "content": "[{:tag=>\"h1\", :text=>\"Example Domain\"}, {:tag=>\"a\", :text=>\"More information...\"}]",
    "updated_at": "2016-08-04T16:36:19.335Z"
  }
]

Get a specific url content :

Request: GET /web_pages/2 with no parameter

Response:

{
  "id": 2,
  "url": "https://example.com",
  "content": "[{:tag=>\"h1\", :text=>\"Example Domain\"}, {:tag=>\"a\", :text=>\"More information...\"}]",
  "updated_at": "2016-08-04T16:36:19.335Z"
}

Remove a specific url content :

Request: DELETE /web_pages/2 with no parameter

Response:

{
  "status": "deleted"
}

All requests at glance :

Request url Request method Request Params Response
/web_pages GET None Get all saved contents
/web_pages/:id GET None Get a specific url content
/web_pages POST web_page[url] Save content of a url
/web_pages/:id PATCH/PUT web_page[url] Update previous saved content
/web_pages/:id DELETE None Remove a specific url content

rails_api_demo's People

Contributors

tauhidul35 avatar

Watchers

James Cloos avatar  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.