Summarized using AI

Lightning Talk: Building REST API with Grape by

William Notowidagdo • June 26, 2014 • Singapore • Lightning Talk

Introduction

In this lightning talk presented by William Notowidagdo at the Red Dot Ruby Conference 2014, the focus is on using the Grape framework to build REST APIs in Ruby. Grape provides a simplified DSL (Domain Specific Language) and is designed to work with Rack, making it a powerful tool for creating APIs that adhere to best practices.

Key Points Discussed

  • Introduction to Grape: Grape is introduced as a micro framework designed for building RESTful APIs in Ruby. It emphasizes simplicity and a straightforward approach to defining resources and their methods.

  • Features of Grape: William mentions several important features of Grape, including:

    • Error Handling: Grape includes a helper for defining error responses, allowing developers to specify response codes and return JSON instead of just textual messages.
    • Versioning: There are multiple strategies for API versioning provided by Grape:
    • Path versioning (e.g., /v1/resource)
    • Header versioning using custom headers
    • Accept headers for versioning requests
    • Parameters-based versioning, which allows easier tracking of API versions.
  • Response Formats: Grape can handle various response formats, including:

    • JSON
    • XML
    • Plain text
    • JSONP for cross-domain requests.
  • CORS Support: The framework offers support for CORS (Cross-Origin Resource Sharing), essential for APIs that need to be accessed from different domains.

  • Authentication: Grape supports multiple authentication strategies, providing built-in helpers to facilitate user authentication and authorization processes.

  • Testing: The talk briefly touches on best practices for testing your Grape APIs to ensure reliability and correctness.

Conclusion and Takeaways

William concludes by encouraging developers to consider using Grape for their next REST API project, highlighting its robust feature set and design sensibilities that align with best practices in API development. He emphasizes that, while only a few features were discussed in the brief session, Grape has much more to offer, and he invites attendees to explore its capabilities further, encouraging innovation in their API development endeavors.

Lightning Talk: Building REST API with Grape by
William Notowidagdo • June 26, 2014 • Singapore • Lightning Talk

How to use grape to build a REST API that applying best-practices patterns.

Handling errors
Versioning
Pagination and partial response
Multiple formats
Handling exceptions
Logging
Authentication
Testing

Help us caption & translate this video!

http://amara.org/v/FGZH/

Red Dot Ruby Conference 2014

00:00:00.550 I good afternoon people up to give you a
00:00:25.689 good introduction to grip well actually
00:00:27.880 we're not going to build a recipe I with
00:00:30.009 grape on five minutes so the point I
00:00:33.519 tried to make is to give you a quick
00:00:35.769 introduction to grip my name is William
00:00:38.199 I'm from Canada ma ruby-on-rails company
00:00:40.300 in Indonesia so what is great where is
00:00:43.719 the risks like API micro framework for
00:00:45.609 Ruby it is design and running wrecked
00:00:47.589 and it's provide a simple dsl this is a
00:00:51.570 usage example of grip as you can see
00:00:54.969 there are a few diesel we can use like
00:00:59.079 prefix results and get you can catch the
00:01:03.280 idea we define the resource and we
00:01:05.230 define the method behind the resource a
00:01:08.650 few of our great features I'd like to
00:01:13.650 present today is only three features but
00:01:16.840 there is a lot more feature of grape
00:01:18.580 that you can see at at the github first
00:01:23.260 is racing exception versioning an
00:01:25.390 authentication and racing exception you
00:01:29.050 can use a helper named error and then
00:01:33.670 you can define what code you want to
00:01:35.740 return to the client but also you can
00:01:39.130 return a JSON instead of message and
00:01:45.720 then we have a functioning there are
00:01:48.130 four versioning strategy that provided
00:01:51.550 by grip the first editor vault is Pat
00:01:53.890 using pad like this and then using
00:01:57.580 header is simply like this like using
00:02:00.760 handle and vendor and then accept
00:02:04.630 version header and then the parameters
00:02:09.460 as you can see on the blue line over
00:02:12.430 there is it AP Ferg
00:02:14.470 v1 but you can change the AP verb to
00:02:17.830 whatever you want then I like to
00:02:20.410 introduce you the API for months well a
00:02:22.150 grip provide us with the four formats
00:02:27.030 based on XML and also txt here we define
00:02:32.350 the response always on this on and then
00:02:36.700 also grip support for the JSONP you can
00:02:40.780 use a wreck jsonp also grab you a
00:02:45.990 provide us with red course so you can
00:02:49.240 use course on your rest api the last
00:02:54.010 part i want to introduce you with grip
00:02:56.080 is a dedication education web provide us
00:03:00.250 with basic HTTP education digest
00:03:04.870 application on also when you want to use
00:03:08.530 for out you can use word an oratorical
00:03:11.050 up that's all for me and I hope you
00:03:13.240 consider grip in your next rest api
00:03:16.240 project thank you
00:03:23.319 you
Explore all talks recorded at Red Dot Ruby Conference 2014
+20