zoukankan      html  css  js  c++  java
  • Grape-demo1

    Grape,为API设计而生DSL(Domain Specified Language),官网地址: http://intridea.github.io/grape

    http://intridea.github.io/grape/docs/index.html

    (1)描述性的API构建方式,代码可读性非常强

    (2)提供了构建Restful API的一套工具,如参数约束,路径约束,版本管理等

    (3)提供了JSON/XML/TXT格式的渲染工具

    demo的地址是https://github.com/shiralwz/grape_api

    module HelloApi
      require 'grape'
    
      class OneAPI < Grape::API
        resource :apis do
          format :json
    
          get 'hello' do
            {message: "hello #{params[:name]} via GET"}
          end 
    
          post 'hello' do
            {message: "hello #{params[:name]} via POST"}
          end 
        end 
    
      end 
    
    end
    Rails.application.routes.draw do
    
      mount HelloApi::OneAPI => '/' 
    end

    rails s

    localhost:3000/apis/hello.json?name=mike

    如果不需要apis这个命名空间可以直接删除 app/model/hello_api.rb里的第五行 resource :apis do 和第十五行 end

  • 相关阅读:
    algorithm
    jstl
    jsp
    cookie
    变量和方法调用过程中会出现的参数传递
    http请求
    weblogic 的安全域问题
    web service
    行业充电
    客户端生成web service
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/4861392.html
Copyright © 2011-2022 走看看