Does grape provide a template to build services - ruby-on-rails

https://github.com/intridea/grape
Is there a way to automatically generate a template for an application which will use grape to provide REST like interfaces. I am looking for something like "rails new app" which will provide me the skeleton to build on. If not what should I be using?

Not that I know of, but there are several example apps with different stacks and functionality on their wiki.
You can mix and match from what you see there, or just clone one of them to get started.
Also, Grape's DSL itself will guide you towards REST. You declare resources and then use the http verbs to define the requests.

grape-starter seems to be what you're looking for.
Install the gem (gem install grape-starter) and create your new API with grape-starter new awesome_api.
For more options, such as choosing an ORM, or setting the prefix, use grape-starter -h. I recommend to have a look on the README.

Related

versioning or using different gems for next API verion

I have written some Rails API little long ago. I used namespace,module for making different versions of it.
Now I need to move my APIs to next version. Where I need to use different gems to achieve the requirement(need to add and delete some extra gems). While keeping the present version running for some more time.
I can use namespace, modules for routes and business logic changes. But how can I specify different gems for this version of API?
Does creating a separate git branch is the solution?
or
should I use different Gemfile.
How should I achieve this?
In same application if you want to add a new Gemfile, then I think it will be better option to create a engine and keep it inside vendors folder, so it will be inside your application and you will get separate routes, namespaces and Gemfile for that.
You can check the link given below about engine development.
http://guides.rubyonrails.org/engines.html

RoR: Swagger does not update api-docs

I have swagger-ui_rails integrated in my existing Rails app. I have added a new model "Book" in my application and now want to update my api-docs. How can I do that ?
I am trying rake swagger:docs but that does not change anything.
Also there is no books_controller in app/controller/api/v1/ direcotry, where other controller exists already.
I am new to Rails and Swagger, so please ignore if i am missing something basic.
Since you mention you define your controllers for the API, I presume you have a home-brewn API. This is ok, but then you will have to generate the swagger documentation by hand. That is ok, but not something I can help you with.
However if you use grape for your api, you can then use the grape-swagger gem. Grape will replace your controllers for the API for you. It is more like a DSL describing your API, which includes the code to be executed. The grape-swagger gem will automatically parse the grape definition and convert it to swagger documentation.
It offers extra options too, like write descriptions in Markdown. The grape-swagger gem is awesome :)
I like this approach, I build a normal rails app, and use grape to serve the API part. My controllers for the UI and API would be different anyway.

What would be ideal way to share functionality between Rails apps?

I have a number of view helpers I use on almost every project, a set of useful rake tasks, minor extensions to active record, extensions to some gems (inherited_resources).
I'm wondering, what would be a good way to manage these 'snippets'? I wouldn't want to manage a gem for each snippet, or even a gem for each 'type' of snippet. Would it suffice to bundle this into a personal gem? Maybe add the option to specify which helpers/extensions to include in the project?
I could use a 'template' application which I could bundle with this code, but the problem here is if I update a snippet on one project, I want to be able to rollout that update on all projects with minimal effort (i.e. bundle update).
With your requirements, I would bundle it all in a base-zenph-gem and use it in every one o your projects, as it is the best way to have synchronized code over different projects.
Also, make a good documentation for it, as if anyone inherits one of those projects would love to know what is going on.
Instead of a gem with Rails you can create an engine which contains reusable functionality, then you can specify the use of the engine within your applications.
You can read more about it in the Rails documentation: Rails Engines

Reusable part of application

I want to create a sms payment engine and reuse it in several applications. It would be best to be able to just copy/paste one directory, maybe configure some minor stuff and just have it working (with views, controllers, etc.).
What's the best way to do this? Of course I'm not asking about this sms thing but about the way to create an isolated piece of application. It's something like a helper application inside of the major application.
There a three ways to build Rails extensions : plain-old ruby code, Railties and Engines.
Railties and Engines allow you to interact with the Rails framework during the initialization using hooks and therefore extend Rails. Actually, every major Rails component (ActiveRecord, ActionPack, etc.) is a Railtie.
The main difference between a railtie and a Rails engine is that an engine can define its own configuration, models, controllers and views. In a way, an engine is a Rails application you can deploy in another one. In your case, I guess a Rails Engine would be the right choice.
Whatever the option you use, you will have to build a gem to distribute your extension and share it across projects.
Here is a gist explaining both the Railtie and Engine concepts
A guide to starting your own rails engine.
Enginex, a command line tool which creates a Rails 3 Engine
I guess the best way to reuse your code is putting them to a gem, then install that gem.
I think the best way to extract reusable part of your application is to create a RubyGem. You can find a tutorial about creating RubyGems here. And there is a Jeweler, a very nice tool to create RubyGems. More about Jeweler, you can find here

Building an extension framework for a Rails app

I'm starting research on what I'd need in order to build a user-level plugin system (like Wordpress plugins) for a Rails app, so I'd appreciate some general pointers/advice. By user-level plugin I mean a package a user can extract into a folder and have it show up on an admin interface, allowing them to add some extra configuration and then activate it.
What is the best way to go about doing this? Is there any other opensource project that does this already? What does Rails itself already offer for programmer-level plugins that could be leveraged? Any Rails plugins that could help me with this?
A plugin would have to be able to:
run its own migrations (with this? it's undocumented)
have access to my models (plugins already do)
have entry points for adding content to views (can be done with content_for and yield)
replace entire views or partials (how?)
provide its own admin and user-facing views (how?)
create its own routes (or maybe just announce its presence and let me create the routes for it, to avoid plugins stepping on each other's toes)
Anything else I'm missing?
Also, is there a way to limit which tables/actions the plugin has access to concerning migrations and models, and also limit their access to routes (maybe letting them include, but not remove routes)?
P.S.: I'll try to keep this updated, compiling stuff I figure out and relevant answers so as to have a sort of guide for others.
You might want to check out mephisto, it's a blogging software built with ruby on rails and has add-on plugin support. Not sure if it works how you are thinking of, but might give you some good insights. The source can be found on GitHub.
You should look at deface gem. It allows to customize rails views, adding content via hooks and replacing whole views/partials. Spree is using this gem so you can look also at spree. Beside views they also have other solutions for customizing application so you can find more answers to your questions.

Resources