Removing all database access capability from rails 5.x client app - ruby

I am still fairly new to ruby and Ruby on Rails framework.
Rails --api only project is great for just getting into bare bones rest API development without any of the unneeded extras.
I would always build a web API app to handle my data access and domain logic.
I would create a separate rails app for the front end web client. Maybe this seperation of tiers is not always necessary for small or 'pet' projects but I prefer this architecture.
I am trying to find the best way to remove the data access related code and gems from my client project as I will never access the database.
Is there aclean way to do this automatically in a similar way that --api switch includes only things relevant to API app?
It's not the end of the world doing this manually but it would be nice if I could write a bash script that I can pass a project name and it would build me 2 shell projects - 1 API, 1 client - with only the things I would usually need at each level.
Any suggestions about this are greatly appreciated.
Thanks in advance!

Related

One-click OpenAPI/Swagger build architecture for backend server code

I use swagger to generate both client/server api code. On my frontend (react/ts/axios), integrating the generated code is very easy: I make a change to my spec, consume the new version through NPM, and immediately the new API methods are available
On the server side, however, the process is a lot more janky. I am using java, and I have to copy and paste specific directories over (such as the routes, data types etc) and a lot of the generated code doesn't play nice with my existing application (in terms of imports etc). I am having the same experience with a flask instance that I have.
I know that comparing client to server is apple to oranges, but is there a better way to construct a build architecture so that I don't have to go through this error prone/tedious process every time? Any pointers here?

Can I have two or more web processes using Heroku

I'm trying to implement reasonably complex architecture using Heroku. I have a Java application that reads/writes data from one source using REST and puts results onto a queue using RabbitMQ. A Django application then reads from this queue parsing data collected then saves to it's database. The Django application feeds Android and ISO apps through GraphQL. The problem I have is Heroku only seems to let me define one web process in my Procfile where in fact I need two. One for the Java application and one for the Django application. Is there anyway I can make this work?
There is no un-hacky / good solution to this. And as the comments stated, it is a bad idea to combine codebases here.
Following Heroku's ideas here, you would split these into separate applications/services that communicate to each other via HTTP or the queue.
Many addons you can attach to multiple applications if they are shared. So you have the same queue.

Spring-mvc integration with reactjs?

I am trying to integrate spring-mvc and reactjs, but it's too poor example, but I like flux architect of reactjs so that i strongly want to integrate reactjs with springmvc!
I want to use reactjs as a client side, springmvc as a rest backend. Can you provide me some example or tutorial to do this? I've searched on google but it's very poor result. Please help me.
Thanks you very much
This answer might not be what you want, but I would advise you not to integrate the two of them. If they communicate over HTTP/WebSockets, they are already decoupled, and it might just cause you pain to couple them.
Advantages of decoupling the frontend and backend into separate projects:
People with experience only in React or Spring can contribute without getting confused by the other stuff.
The tooling/build you need for a Spring project is quite different from what you need for a frontend project, and mixing this into one code base can get pretty confusing.
If they're decoupled from the start, it gets easier to add other clients that use the backend API. By having them as separate projects, you're less likely to develop the backend in a way that's very tied to the frontend.
The frontend and the backend should use different versions and be shippable independently of each other. What if the backend team is currently doing a major refactoring, but the frontend team just fixed a critical bug and wants to ship a new release?
As soon as you add asset caching to your frontend project (like putting the files on a CDN, using the HTML5 application cache or the new Service Worker API), you have to prepared for getting requests to your backend from "old" clients. By separating them, it's easier to think about and plan for stuff like that on the backend.
I could probably list a couple of more benefits, but these are the ones I consider has the largest impact. There are of course some benefits of integrating the two of them, but those tend to get smaller and smaller as the project grows/matures.

Can I create a simple website to accept input and display, without Rails, database or external web server?

I am trying to see if I can create a simple website, like a blog, using only Ruby. No Rails or a database or outside web servers. I plan to store the data in a file for persistence.
I wanted to use TCPServer, CGI, and Net::HTTP.
Is there an easier way I can use?
There are a lot of moving parts when designing a website.
Depending on the purpose of the exercise, you might want to consider using a very simple web framework like Camping, Sinatra, or Ramaze. This is probably the best solution if you're trying to get a top level understanding of web programming because it only has exactly what you need (Camping is less than 4k!) and handles stuff like routing.
Building a web server is more an exercise in HTTP parsing. You might want to omit the framework and try to build something on top of Rake (an API for lots of popular web servers) and a simple web server like Webrick or Thin.
You could also try Espresso
It is easy to learn and fast to run.
And offers all the liberty you need for creation process.
Also it has no hidden "fees", everything is transparent.

How to use activerecord alone?

I prepare to develop one project, which has no UI. The project just need to interact with database, so is there any example for reference ?
Does your app have ties to a Rails-based app and need to read the Rails configuration files? Or, is it entirely stand-alone and have no Rails interaction?
ActiveRecord is OK for that, but if I don't need Rails compatibility I use Sequel. It's a great ORM that I find to be much more flexible.
If you need Rails compatibility and want to use ActiveRecord, look into using rails runner. From the docs:
runner runs Ruby code in the context of Rails non-interactively. For instance:
$ rails runner "Model.long_running_method"
Rails runner is for command-line apps that don't need the HTTPd server or user-interface of Rails. I use them for things like an app that runs daily to ftp files from a site for analysis. It has to write to the database, so it has access to all the models I've defined, but it never needs to present anything to the user since it is invisible to them.

Resources