I am new to Rails and I am creating a RoR web application, their is a mobile component that will connect (CRUD) to the default db I am creating. I need some guidance in writing the web service component and what valid endpoints should look like in this type of app. Any direction would be helpful, thanks.
Ruby on Rails provides restful web service development out of the box, i.e. any app developed on RoR is by nature a RESTful web service. To answer the specifics of your question, consider checking out this SO thread
Related
I have an existing RoR web application which currently uses Devise for authentication.
I am planning on adding API functionality in one manner or another for a mobile backend.
Would you recommend adding API functionality to the web application and using JWT, for example, to enable mobile authentication. Alternatively, would you have two separate applications, a web application and an API, sharing the same Postgres instance on Heroku?
I see pros and cons both ways, but it would seem to me that separating it into two applications would outweigh adding API functionality to the web app. Perhaps, it would make most sense to start over with just an API and add mobile app client and web application client functionality.
Creating a new API only backend might be easier at first, but you would have to copy all your app logic in the models over and keeping both sides up to date will be a pain. You can do it in the same rails app if you namespace the new API so that all calls are under a /api_v1 or something like that. Here is an article that show how you can have different versions of your API.
JWTs for authentication is a great way of doing it and Devise can support them by adding a gem like devise-jwt since adding a route and handling the creation and updating of tokens by yourself is a lot of work.
For the API itself you might want to consider using JSON:API with the jsonapi-rails gem or GraphQL with the graphql gem. This way when someone wants to use your API they can use an adapter for their framework that can talk to that kind of API and not have to worry about the structure of what it returns. There are adapters for both APIs that work with Andrioid, IOS, Ember, React, and all other major frontend frameworks.
Is it possible to write soap based web services using ruby on rails framework. If yes, can someone please point to a learning resource
Yes, you can write SOAP web services using Rails, However Rails is moving in favour of a REST web service approach. So my personal opinion is if you are starting a brand new Rails app with SOAP web services, consider some other programming language like JAVA, because that has more tools to easily create SOAP web services.
But nowadays all the webservices going towards REST, because of the simplicity it has. Almost all major sites has a REST API.
Furthermore if you are still planning to go ahead with Rails, savon is an interesting gem that you should probably look at.
I have a Rails application that right now is pretty standard: Heroku/PostgreSQL backend, users go directly to my site to update data, there's no mobile app or anything. We're going to start licensing out the tech to other companies, so that different versions of the interface live on company1.mywebsite.com, company2.mywebsite.com, etc, where all of these interfaces share the same database.
I want some advice on how to go about building this. Do I create a separate Rails app for company1, company2, etc (with a lot of redundant code) and then set up each of them with API keys to query my master app, using its RESTful routes?
Any tutorials to point me to would be great as well.
I recommend you the book Service Oriented Design with Ruby and Rails, by Paul Dix. It has a lot of info about the kind of system that you want to build.
To answer your question:
Build an API server. It serves a JSON – for example – RESTful interface.
api.mydomain/client1/users.json
Build a frontend server. It consume the API service – using typhoeus for example – and serves the final pages. It uses a subdomain or domain name for identification of different clients.
client1.mydomain/users
We have a similar "platform".
What we did:
build a master API app (REST + Push)
build a core plugin for rails which has all the shared code
build a separate rails app for each client which has all the client specific code
We are using this setup for 3 years now and I'm pretty happy with it.
I developed a web site using rails 2.3.8, and a IM server using openfire(java). I want to share some data between them, or exactly rails as provider, openfire as consumer. A possible way is using web service. But it seems that rails 2.x has deprecated the default SOAP support, I installed the gem activewebservice, but there is lack of documents to show how to using it. I googled an example in IBM's site, but there seems something wrong to follow this guide in rails 2.3.8. Can anyone give me an example?
I know there is another way to provide the web service is using rails' default RESTful-type web service, but how to configure the java side to support this?
Rails has support for RESTful web-services OOTB, so if you have developed your rails application using scaffold generator then your application is already providing a RESTful API. Now as your IM server is the consumer, all you have to do is to make your IM server call the RESTful API provided by the rails application.
Calling RESTful API means sending HTTP (GET/POST/PUT/DELETE) requests to the REST server(Rails App). So all you need to do, is plugin some java code to the openfire server which will send the HTTP requests adhering to the REST conventions and send/receive data in a suitable serialization format(XML/JSON/etc). There is a plugin mechanism in openfire which which probably may help you achieve this.
As far as RESTful calls are concerned, this can be achieved in any of the below methods:
Use a REST Client library provided by JAX-RS implementations like Jersey, Apache wink, etc.
Use any HTTP client library to send/receive HTTP requests/response and a XML/JSON/etc library to serialize/de-serialize the data.
I know they removed ActionService out of RoR and opted for RESTful web services. I want to know if Rails is a good choice of a framework for consuming XML/SOAP based web services. Can anyone point out some nice resources/tutorials on how to consume a SOAP based web service in ROR?
This is a pretty good step-by-step tutorial for soap4r: [link no longer works]