Angular 2 and Rails as a separate applications - ruby-on-rails

Who can tell to me how to create a 2 separate applications: rails backend and Angular 2 frontend and config the data exchange between it. Rails app need to work as a json api. How Angular 2 understand recieved data from rails and how we can send the concrete data to concrete component?
Please some links, articles and so on.
Thank you so much!

The Server
I'm not an expert in the field of ruby, but this tutorial looked good to me:
https://www.codementor.io/ruby-on-rails/tutorial/creating-simple-api-with-rails
The Client
Angular 2 belongs more to my strengths:
Follow up to the official tutorial from google to develope an angular2 app. here is the link:
https://angular.io/guide/quickstart
If you really understand how that starter-tutorial works, you might use a quick-start npm package for a faster start. Be warned! You only use a quick-start package, if you understand the plain way angular 2 should be installed!
The Clients API engine
For the API queries between your client (angular2) and your server (ruby) use this tutorial:
https://angular.io/docs/ts/latest/guide/server-communication.html
I would recommend you to develope only with TypeScript. Dont use EcmaScript (JavaScript) for your client! All the tutorials and the whole community are real hardcore typescript fanatics, so don't even try to convert them :D Just follow them! (To explain why, would take me another post...)
Good luck and have a nice start!

This is really at least two questions: 1) how can a static angularjs app consume json data 2) how can a rails server return json data. Both questions are best answered by simply learning the two frameworks. The harder questions are around designing the api and how to authenticate. All that is really too broad for a single answer except to say go and learn about those four concerns.

Related

Rails with Angular 2 ( for stand-alone web apps)?

I have been learning rails for over 4-5 months.I would say i am intermediate(ish) on rails.Past week, i got interested in angular2.Since it is written in TypeScript, it was little diffrent for me.Can rails do what angular2 can do? I mean single page app things? Should i invest the time to learn it, or just move along with rails? And if i leave angular2, can i still make single page rails apps?
I know this might not be the place for this question, but i haven't got an answer from quora for past 4 days.This question really bothering me mentally and psyhically. It is bothering my mind, and preventing me to learn anything at all.Please help.
Angular is a client side app only.
Rails is a server side app.
Rails would be the more complete package as it can accomplish everything Angular can in it's own way.
There's no definitive answer for this but it really just comes down to what your project's requirements are.
Angular is great for font-end single page client side apps.
Rails is great for server side, database ORM etc.
With that being said there's nothing stopping you from using both in one app. It's a little too broad to cover here.

how to organize outgoing api request urls in rails

I have an application in rails that make request to other microservices using httparty. Other microservices are also written in Rails. Right now, i hard coded all the api urls used in httparty, what will be a more elegant way to organize them?
This is a great question, although it's way too broad to be answered meaningfully here without more specifics on the problem you're solving.
However, if I were you, I'd start by reading the source code for existing API libraries. It's a fantastic way to learn about API design principles from very practical examples in products you likely use every day.
Personally, I've found that the Stripe Ruby SDK (https://github.com/stripe/stripe-ruby specifically, lib/stripe/api_operations), the Slack Ruby SDK (https://github.com/dblock/slack-ruby-client), AWS Ruby SDK (https://github.com/aws/aws-sdk-ruby though this one's pretty big), and Github Ruby SDK (https://github.com/aws/aws-sdk-ruby) are all well designed and worth studying.

Is there Getting Started RAILS documentation for someone only interested in developing REST APIs?

Our team will be using Rails for the development of RESTful APIs only. We will use Ember or Angular for our GUI layer and will sometimes just publish our APIs for external consumption. For someone such as myself who doesn't know Rails at all yet, and doesn't really want to learn the View part, finding good "getting started" documentation hasn't been very successful. I've found a few articles on how to build REST APIs, but even these articles seems to assume prior Rails knowledge. Can anyone point me to docs for a Rails newcomer who only wants to build REST APIs? Thanks!
Check out: https://github.com/rails-api/rails-api
This is a starting point for a version of Rails better suited for JS-heavy apps.
Rails API provides: trimmed down controllers and set of generators, specifically built for API type applications.

How to structure Ruby on Rails website

I'm curious to learn Ruby and Ruby on Rails. I have previous experience with PHP and some basic C/Objective C and Java.
I have done a couple of 'Get started with Rails' tutorials and want to try do create a complete site now. I do have some questions.
Is the entire website an app? I mean, sure, the simple 'blog-with-comments' examples fit in a single app. But what if you want more? Say, a forum, a blog, community, shop, task manager and so on (only random examples here... :) ).
Should I split these things into different 'apps' or not? I would still need them to communicate with each other and share user data and so on...
Any ideas?
Regards
Linus
In general, your core competency as a rails app -- that which you provide the most value for your users. You can then supplement from there, so your support section might be GetSatisfaction and live on support.yourdomain.com.
Your online shop could be a link to your shopify page at shop.yourdomain.com, etc.

Getting started consuming web services in a Ruby on Rails 3 application

So I'm getting started learning Rails. Now that Rails 3 is out, I want to stick to learning the Rails 3 way of doing things. One of the things I want to learn how to do is how to consume web services / work with third party REST APIs / create "mashup" applications. I've only done minimal work like this with PHP and pre-built libraries.
Can someone please lead me to some resources, best practices, or give me a quick 101 lesson on how to start working with these types of APIs? What gems should I use? Some sample code to get me started would be much appreciated.
Update: I am specifically trying to use the Google Books API (non-authenticated). Since there is no client library for this API, I'm wondering how other Ruby/Rails developers are working with APIs that don't come with their own Ruby library. That's why I'm looking for a more generic solution to working with "fill in the blank" API.
Update: After some research, I noticed the Net::HTTP library. All the tutorials that talked about it were fairly old. Is this still the best library to use for consuming RESTful web services? Or is there a newer Gem that makes this easier? I just want to know which gem/library I should use, and how to work with the XML/JSON result that is returned.
Update: This presentation was really helpful. It mentions a bunch of different libraries and shows examples of some of the libraries mentioned below: http://www.slideshare.net/pengwynn/json-and-the-apinauts
I'm a pretty big fan of HTTParty.
It's an abstraction layer on top of Net::HTTP with a nice little DSL for consuming web services. Here's a good example of how easy it is to use.
It's not without some warts (lots of dependencies) but it's really the way to go if you're on the consuming side.
I'd recommend REST with Nokogiri:
http://railscasts.com/episodes/190-screen-scraping-with-nokogiri
Nokogiri works well with xml too, not just HTML.
Weary is a really neat DSL for consuming RESTful services.
Clearly inspired by HTTParty but a bit newer and a bit more concise.

Resources