Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
handling API request in views, from alpine to possibly stimulus

I have currently set up alpine to make a POST request to a certain api in my views with the x-init method. The method is quite simple using fetch and then handling the response.

function getDocumentStatus() {
   return {
   isLoading: false,
   status: null,
   fetchStatus() {
      this.isLoading = true;
      fetch('API_URL', {
         method: 'POST',
         headers: {
            'Content-Type': 'application/json',
            'Access-Control-Allow-Origin': '*'
         },
         body: JSON.stringify({document_uuid: '<%= @document_uuid %>'}),
         })
         .then(response => response.json())
         .then(data => {
         this.isLoading = false;
         if (data === 'pending') {
            this.status = 'Waiting for results'
         } else if (data === 'signed') {
            this.status = 'Results signed'
         } else if (data === 'new') {
            this.status = 'Sent'
         }
      })
   }
   }
}

However I've recently found a ruby wrapper for this api and since I'm doing also quite a lot more with the particular api I've started to incorporate the wrapper to my app.

Using this wrapper I can simply call

client.document.status(document_id: xxx)

to fetch the status for a document. I'm trying to figure out how can I use this to replace the current logic in the views and get rid of alpine to possibly something like a stimulus controller? Any suggestions on how to approach this would be appreciated!

Something I've looked at is https://stimulus.hotwired.dev/handbook/working-with-external-resources but it seems that I would need to have something like a controller action

def status
    client.document.status(document_id: xxx)
end

and then a partial for this action which I would then render via stimulus on the view I want to show the results? Seems to me a bit that this would just again be something that wouldn't really belong to the controller(?).

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can try using Sidekiq for processing stuff in the background. Then in your front-end you can update the page as soon as it's done. This sounds simple enough, however Sidekiq doesn't provide anything to monitor statuses of your jobs. In pro version you can use batches and there, you have a callback functionality, however you can check out recommended gems to implement that.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!