Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7929667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:09:43+00:00 2026-06-03T20:09:43+00:00

I’m working with zabbix and writing an interface to interact with the zabbix api.

  • 0

I’m working with zabbix and writing an interface to interact with the zabbix api. Since zabbix exposes a jsonrpc interface I decided to use MojoX::JSON::RPC::Service. The problem I’m running into is that I’m now faced with interacting with other services written using Mojolicious::Controllers where they’re expecting a Mojolicious::Controller objects. There is no Mojolicious::Controller object available when using MojoX::JSON::RPC::Service.

my $obj = $rpc_obj->register(
               'retrieve',
               sub {
                    # do stuff
               },
               { with_mojo_tx => 1 }
);

That registers a route called ‘retrieve’. When the route is accessed and the anonymous
subroutine is run, the subroutine has access only to the Mojo::Transaction::HTTP object.

So, I don’t have access to the app for using plugins and the stash and other things that Mojolicious offers. Is there a way to incorporate Mojolicious::Controller with MojoX::JSON::RPC::Service?

I could rewrite it to use a Mojolicious::Controller but I’m trying to avoid that if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:09:44+00:00Added an answer on June 3, 2026 at 8:09 pm

    You should consider to use MojoX::JSON::RPC::Dispatcher, as it inherits all attributes from Mojolicious::Controller

    SYNOPSIS:

    # lib/your-application.pm
    
    use base 'Mojolicious';
    use MojoX::JSON::RPC::Service;
    
    sub startup {
        my $self = shift;
        my $svc = MojoX::JSON::RPC::Service->new;
    
        $svc->register(
            'sum',
            sub {
                my @params = @_;
                my $sum = 0;
                $sum += $_ for @params;
                return $sum;
            }
        );
    
        $self->plugin(
            'json_rpc_dispatcher',
            services => {
               '/jsonrpc' => $svc
            }
        );
    }
    

    [UPDATE]
    Hook Example:

    package Application;
    use Mojo::Base 'Mojolicious';
    use Application::Firewall;
    
    # This method will run once at server start
    sub startup {
        my $app = shift;
    
        # Routes
        my $r = $app->routes;
    
        # Validation Middleware
        $app->hook(
            before_dispatch => sub {
                my $self = shift;
                my $data = $self->req->params->to_hash;
                my $vald = Application::Firewall->new($data);
    
                # mojolicious bug at the time of coding
                delete $data->{""} if defined $data->{""};
    
                $app->{input} = {};
    
                if ( keys %{$data} ) {
    
                    # validation the submitted data
                    unless ( $vald->validate( keys %{$data} ) ) {
                        $self->render(
                            text   => join( "", @{ $vald->errors } ),
                            status => 500
                        );
                        return 0;
                    }
    
                    # Helper (optional)
                    # create a helper to get access to the transformed data
                    # if your validation rules had/has filters
                    # Note! due to a bug in the params function we must do this
                    # (... i know, so what)
                    $app->{input} = {
                        map { $_ => $vald->{fields}->{$_}->{value} }
                          keys %{ $vald->{fields} }
                    };
    
                }
    
                return 1;
            }
        );
    
        # Normal route to controller * with auto-matic input validation *
        $r->route('/')->to(
            cb => sub {
                my $self = shift;
                $self->render(
                    text => 'Hello ' . ( $app->{input}->{foobar} || 'World' ),
                    status => 200
                );
            }
        );
    }
    
    1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am writing an app with both english and french support. The app requests
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.