building an api using grape

14
Presented By Visnupriya. J. R Building an API using

Upload: visnu-priya

Post on 14-Jul-2015

181 views

Category:

Software


4 download

TRANSCRIPT

Page 1: Building an API using Grape

Presented By

Visnupriya. J. R

Building an API using

Page 2: Building an API using Grape

©2014

•What is Grape

•Basic Usage

•Versioning

•Format

•Error Handling

•Restful-Model-Presentation

•Testing

•Documentation

Agenda

Page 3: Building an API using Grape

©2014

•Powerful API framework

•Designed to run on Rack Application

•To fit into Sinatra and Rails Application

•Grape framework mean "Generalized Rapid API Erector"

What is Grape?

Page 4: Building an API using Grape

©2014

module API

class Events < Grape::API

version 'v1‘

get :hello do

{ hello: "Spritle" }

end

end

end

Basic Usage

Page 5: Building an API using Grape

©2014

•Path

•Header

•Accept-Version Header

•Parameter

Versioning

Page 6: Building an API using Grape

©2014

content_type :xml, ‘application/xml’

content_type :json, 'application/json‘

default_format :json ##Override default format

format :json ## for single format

API Format

•Support XML, JSON, BINARY, and TXT content-types

•Default format is :txt

Page 7: Building an API using Grape

©2014

error! ‘Access Denied’, 401

### return JSON format

error!({error: “unexpected error”, detail: “missing widget”}, 500)

### rescue all exceptions and return in API format

rescue_from :all

Error Handling

Page 8: Building an API using Grape

©2014

•To represent data using ‘present’ method

–Grape Entities

–Hypermedia

–Rabl

–Active Model Serializers

Restful-Model-Presentation

Page 9: Building an API using Grape

©2014

•Can test API using RSpec

•RSpec supports API testing framework with airborne gem

•https://github.com/brooklynDev/airborne

Write Testing

Page 10: Building an API using Grape

©2014

•Easily can document API using Swagger

•What is Swagger?

•It’s provide web interface using Swagger UI

•Run doc at http://localhost:3000/apidoc

Documentation

Page 11: Building an API using Grape

©2014

•Helper method

•Description

•Pagination with kaminari

•Cache

•Content Negotiation

•OAuth 1.0/2.0

More….

Page 12: Building an API using Grape

©2014

•https://github.com/intridea/grape/wiki

•https://github.com/intridea/grape#what-is-grape

•http://confreaks.com/videos/475-rubyconf2010-the-grapes-of-rapid

•http://funonrails.com/2014/03/building-restful-api-using-grape-in-rails/

•http://intridea.github.io/grape/docs/

References

Page 13: Building an API using Grape

©2014

Q&A?

Page 14: Building an API using Grape

©2014

WE BUILD APPS THAT PEOPLE LOVE TO USE

Enterprise Web Applications Development

Cross-Platform Business Mobile Apps Development

Social Media Integrated Applications Development

Product Development Services