How do I make JSON api calls?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I make JSON api calls?

Charlie Lor
I'm very new to ruby on rails. I need a view that will show the data from a JSON API calls. How do accomplish this? Do I need to create a model for this? I assumed the controller is the place to put my API calls code, correct?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/98a65791-de22-4d63-ac39-a40d035cfdeb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I make JSON api calls?

Colin Law
Where is this API? Is it some s/w running on the same machine as
node-red or a web service or what?  Tell us a bit more about it.  How
would the API be called from another application?

Colin

On 5 June 2017 at 16:56, Charlie Lor <[hidden email]> wrote:

> I'm very new to ruby on rails. I need a view that will show the data from a
> JSON API calls. How do accomplish this? Do I need to create a model for
> this? I assumed the controller is the place to put my API calls code,
> correct?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/98a65791-de22-4d63-ac39-a40d035cfdeb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvK-p_d5kiBcTOADM%3DjbvPLOBFNWE3kU5SDtvoeKjmecw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I make JSON api calls?

Colin Law
Oops, ignore me, I forgot which mailing list I was on. I must remember
to engage brain before typing, sorry

Colin

On 5 June 2017 at 21:58, Colin Law <[hidden email]> wrote:

> Where is this API? Is it some s/w running on the same machine as
> node-red or a web service or what?  Tell us a bit more about it.  How
> would the API be called from another application?
>
> Colin
>
> On 5 June 2017 at 16:56, Charlie Lor <[hidden email]> wrote:
>> I'm very new to ruby on rails. I need a view that will show the data from a
>> JSON API calls. How do accomplish this? Do I need to create a model for
>> this? I assumed the controller is the place to put my API calls code,
>> correct?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [hidden email].
>> To post to this group, send email to [hidden email].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/rubyonrails-talk/98a65791-de22-4d63-ac39-a40d035cfdeb%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvUM6Ri%3Dyetun2idSS544gQdwOhCOE4QquWMTsiXYhG7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I make JSON api calls?

Jason Fleetwood-Boldt
In reply to this post by Charlie Lor

See Net::HTTP.

I would send you a link but ruby-doc.org is down

You do not need a model, in fact you probably shouldn't have one unless you want to store the data you receive somewhere. (even then you don't need a model)

You should think outside of the MVC box. Just because DHH put 3 folders named "models", "views", and "controllers" doesn't mean you have to put all of your ruby code there, especially if MVC doesn't fit your needs.


One specific scalability thing you might consider is that a in-request server-to-server API is generally considered non-scalable, but it depends on the response time on the remote API. If it is very fast maybe it will work. If it is slow, it will slow down your website.

If I'd were to build something really scalable, I'd fetch the external data in a background process and store it — database or otherwise — so that when the user looks at it it comes from cached place (may be a few minute stale). Then a background job runs on an as-needed basis to keep the data fresh. That's the scalable way to do it. 

But if scalability isn't a concern you can just make the API call, format the data the way you want it, and show it to the user. 

Your question was very high level and so was this answer. As a more specific/detailed question if you want a more specific/detailed answer. Your mileage may vary. 

-Jason

On Jun 5, 2017, at 11:56 AM, Charlie Lor <[hidden email]> wrote:

I'm very new to ruby on rails. I need a view that will show the data from a JSON API calls. How do accomplish this? Do I need to create a model for this? I assumed the controller is the place to put my API calls code, correct?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/98a65791-de22-4d63-ac39-a40d035cfdeb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

If you'd like to reply by encrypted email you can find my public key on jasonfleetwoodboldt.com (more about setting GPG: https://gpgtools.org

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/805D4E44-E2D3-4CA4-A7EC-23F7C7FE5A94%40datatravels.com.
For more options, visit https://groups.google.com/d/optout.