GithubHelp home page GithubHelp logo

easy_api_doc's Introduction

EasyApiDoc

This project rocks and uses MIT-LICENSE.

Installation

Add to your application's Gemfile:

gem 'easy_api_doc'

or

gem 'easy_api_doc', :git => '[email protected]:AbleTech/easy_api_doc.git'

Usage

Config files

See test/dummy/doc/api_doc.yml for an example YAML config file.

This project is a work in progress, and doesn't hold your hand with validating the config file format yet. It's current supported format is: (nodes named with <> are to be named whatever you like)

Use the rails convention of specifying dynamic url paramaters via :id

api:
  <version_number>:
    defaults:
      domain: api.example.com
      protocol: http
      ...
    <namespace>:
      description: "..."
      detail:      "..."
      formats: "json, xml"
      authentication:
        type: basic
        user: admin
        password: password
      resources:
        <users>:
          description: "..."
          actions:
            <update>:
              http_method: POST
              uri: /users/:id
              description: "..."
              parameters:
                <id>:
                  type: integer
                  example: 1
                <account_type>:
                  type: string
                  default: personal
                <nested_record>:
                  <nested_attr>:
                    type: string
                    example: [email protected]

Routes

Add to your application's routes.rb:

mount EasyApiDoc::Engine => "/api_docs"

Options

Put your options in an initializer, like config/initializers/easy_api_doc.rb

Example:

EasyApiDoc.options do |options|
    # options here
end

Authentication

By default authentication is non-existent and anyone can access the docs. You can specify authentication like so...

options.authenticate_with do
    authenticate_user!
end

Whatever you pass to authenticate_with is evaluated as a before_filter on EasyApiDoc controllers. The example above uses the Devise method authenticate_user!

Authorization

There is no authorization unless specified. Anyone can access anything.

Custom

Whatever you pass to authorize_with is evaluated as a before_filter on EasyApiDoc controllers.

options.authorize_with do
  redirect_to root_path unless user.is_admin?
end

CanCan

You can use CanCan to authorize access.

You need to send :cancan to the authorize_with option. You must also send (as a second parameter) the name of the method used to access the current user. e.g. with Devise this is current_user.

options.authorize_with :cancan, :current_user

easy_api_doc's People

Contributors

nigelramsay avatar

Watchers

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