• Stars
    star
    508
  • Rank 83,652 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 14 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

makes creating API responses in Rails easy and fun

acts_as_api makes creating XML/JSON responses in Rails 3, 4, 5 and 6 easy and fun.

It provides a simple interface to determine the representation of your model data, that should be rendered in your API responses.

In addition to Rails it theoretically can be used with any ruby app and any database (ActiveRecord, Mongoid and ActiveResource are supported out of the box) as it only has few dependencies.

The lib is very fast in generating your responses and battle tested in production with platforms like Diaspora or flinc.

Introduction

acts_as_api enriches the models and controllers of your app in a Rails-like way so you can easily determine how your API responses should look like:

class User < ActiveRecord::Base

  acts_as_api

  api_accessible :public do |template|
    template.add :first_name
    template.add :age
  end
  # will render json: { "user": { "first_name": "John", "age":  26 } }

  api_accessible :private, extend: :public do |template|
    template.add :last_name
    template.add :email
  end
  # will render json: { "user": { "first_name": "John", "last_name": "Doe", "age":  26, "email": "[email protected]" } }

end

Getting started

A nice introduction about acts_as_api with examples can be found here:

http://fabrik42.github.com/acts_as_api

See the Wiki for a lot of usage examples and features:

https://github.com/fabrik42/acts_as_api/wiki

There are a lot of how-tos like:

Features:

  • DRY templates for your api responses
  • Ships with support for ActiveRecord and Mongoid
  • Support for Rails 3/4 Responders (extracted to responders gem since Rails 5)
  • Plays very well together with client libs like Backbone.js, RestKit (iOS) or gson (Android).
  • Easy but very flexible syntax for defining the templates
  • XML, JSON and JSON-P support out of the box, easy to extend
  • Minimal dependecies (you can also use it without Rails)
  • Supports multiple api rendering templates per model. This is especially useful for API versioning or for example for private vs. public access points to a user’s profile.

Requirements:

  • ActiveModel (>= 3.0.0)
  • ActiveSupport (>= 3.0.0)
  • Rack (>= 1.1.0)

Links

Downwards Compatibility

Note that upgrading to 0.3.0 will break code that worked with previous versions due to a complete overhaul of the lib. For a legacy version of this readme file look here: https://github.com/fabrik42/acts_as_api/wiki/legacy-acts_as_api-0.2-readme

More Repositories

1

responsive_mockups

Takes screenshots of a webpage in different resolutions and automatically applies it to mockup templates.
JavaScript
279
star
2

writing_an_interpreter_in_elixir

Elixir implementation of an interpreter for the Monkey programming language
Elixir
128
star
3

facebook-user.js

A small wrapper that wraps facebook connect in a backbone.js model
JavaScript
54
star
4

node_tile_server

A node.js powered tile server for leaflet to render openstreetmap data
CoffeeScript
17
star
5

pusher

A simple node.js publisher lib for pusher.com
JavaScript
15
star
6

single-file-ruby-programs

Talk: Introducing rbgif and LRuby 1.8.7
JavaScript
12
star
7

traffic-light-client-elixir

A web controlled traffic light for Raspberry PI, powered by Elixir and Nerves
Elixir
11
star
8

cat_facts

Rack middleware that to add cat facts in headers of HTTP responses.
Ruby
11
star
9

traffic-light-server

Configure traffic lights on heroku
JavaScript
9
star
10

fb_cms

A simple website that gets its content via the fb graph api
Ruby
7
star
11

.spacemacs.d

My Emacs/Spacemacs configuration, including org-mode and custom themes
Emacs Lisp
6
star
12

traffic-light-client-raspberry

A web controlled traffic light for Raspberry PI
Ruby
5
star
13

traffic-light-server-elixir

Configure traffic lights on Heroku, powered by Elixir and Phoenix
Elixir
4
star
14

lruby

Logging Ruby - The Ruby alias for the forgetful scripter
Ruby
3
star
15

maptp-service

Provides a ruby interface to the NAVTEQ MapTP web services
Ruby
3
star
16

fabrik42.github.com

my github user page
HTML
2
star
17

work_log

A simple time tracker that logs your work times to a file using a command line interface.
Ruby
2
star
18

espruino-doorbell

Espruino WiFi powered Doorbell notification service for Slack
JavaScript
2
star
19

flocking_elixir

A simple swarm simulation, written in Elixir and Phoenix
Elixir
2
star
20

mechanicon.io

The official MECHANICON website
HTML
1
star
21

deployment_song

Deployment is boring, let's sing-a-long
1
star
22

ankkb_fb

sinatra app that presents fb site data (events, photos, ...) on the web
Ruby
1
star
23

yoloframe

Digital, physical picture frame that I keep in the background of my video calls. It shows only the latest images and everyone can just upload new ones.
HTML
1
star