No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
public
twitter
Gemfile
Gemfile.lock
LICENSE
README.md
config.ru

README.md

test-grape-api

Gems

config.ru 範例

require 'bundler/setup'
Bundler.require

require "vienna"
require "grape"
require "grape-swagger"
require_relative "twitter/api.rb"

module API
  class Root < Grape::API
    format :json

    # CORS
    before do
      header['Access-Control-Allow-Origin'] = '*'
      header['Access-Control-Request-Method'] = '*'
    end

    mount Twitter::API
    add_swagger_documentation
  end
end

# 除了API 還要跑 public 下的靜態檔案
run Rack::Cascade.new [API::Root, Vienna]

Swagger UI

swagger-ui 下載壓縮檔

swagger-ui/dist 下的檔案複製到專案 public

打開 index.html

if (url && url.length > 1) {
  url = decodeURIComponent(url[1]);
} else {
  url = "http://petstore.swagger.io/v2/swagger.json";
}

修改成

if (url && url.length > 1) {
  url = decodeURIComponent(url[1]);
} else {
  url = "http://localhost:9292/swagger_doc.json";
}

Execute

Run command:

bundle exec rackup