Search code examples
ruby-on-railsajaxapi-design

Infrastructure question: How to send/receive data to another website with my rails application?


It's the first time I'm trying this, but I don't know where to start/how to do it. I seem to be lacking some general knowledge on API requests (and their flow) in order to understand the documentation. Therefore, I have some (probably basic) questions on the topic.

Context

In my Ruby on Rails app, bike rental companies can manage all their bikes (reservations, payments etc.).

Goal

I would like to offer a bike rental companies the option to implement a booking form on their own website, so they can let customers make a reservation for a specific bike.

This booking form would then take prices and available bikes from my Rails app to their website and consequently send new reservation data back to the Rails app.

Questions

On the flow of API calls:

  • What would be the order of the API exchange.
    • Is it correct that the 3th party sends an api request for the data, and the Rails app send the requested information back?
    • Furthermore, everytime the Rails application updates relevant information, it should also create an API call?

On the folder/action structure for an API call:

  • How/where should the API call be configured in my rails app?
    • Is it correct that a relevant controller triggers such an action after create/update?
    • In which folder should I create an Ajax request?

Solution

  • you should create api by the following steps:

    1. in the form of website, user fill information and submit them
    2. in the submit action it should call your Rails API (you should create a controller Api::BikesController and an action for example bikes_info). bikes_info API called.
    3. bikes information sent in response of API
    4. web sile get the information display to the user and user select one of that option and click submit button and second API called from your app
    5. "reserve" is the second API name in your app. you should get reservation info and save data in DB and send response to the web site