JSON::...::HTTP(3pm)

πŸ“¦
version 0.11 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME

JSON::RPC::Common::Marshal::HTTP β€” bestie, this is the lil module that converts HTTP::Request and HTTP::Response to and from JSON::RPC::Common calls and returns. Like a translator but for RPC vibes ✨


✨ VERSION

version 0.11


🌸 SYNOPSIS

okay so here's the whole flow, it's giving main character energy:

use JSON::RPC::Common::Marshal::HTTP;

my $m = JSON::RPC::Common::Marshal::HTTP->new;

my $call = $m->request_to_call($http_request);

my $res = $call->call($object);

my $http_response = $m->result_to_response($res);

πŸ¦‹ DESCRIPTION

This object is your marshalling bestie 🫢 it hands you routines that convert calls and returns to and from HTTP::Request and HTTP::Response objects. Marshalling. Slay.


πŸŽ€ ATTRIBUTES

  • prefer_get β€” when you're encoding a call into a request, this makes it prefer GET.
not reccomended. (that's literally how the original spells it, i'm just the messenger 😭)
  • rest_style_methods β€” when you're encoding a GET request, this uses REST style URI formatting. which means the method is part of the path, not a parameter. iykyk πŸ’…
  • prefer_encoded_get β€” when this is set and a "params" param exists, it decodes it as Base 64 encoded JSON and uses that as the parameters instead of the query parameters.

See <http://json-rpc.googlegroups.com/web/json-rpc-over-http.html>.

  • user_agent β€” defaults to the marshal object's class name plus the JSON::RPC::Common version number. cute, right?
  • content_type
  • accept_content_type
  • content_types
  • accept_content_types β€” when you explicitly set these, they are the values of the "Content-Type" and "Accept" headers to set. periodt.

Otherwise they'll default to application/json with calls/returns version 1.0 and 1.1, and application/json-rpc with 2.0 objects.

  • expand β€” whether or not to use an expander on "GET" style calls. yes or no, that's the whole vibe check.
  • expander β€” an instance of CGI::Expand or a look alike, used for "GET" parameter expansion. 🧚

πŸ’… METHODS

  • request_to_call $http_request
  • post_request_to_call $http_request
  • get_request_to_call $http_request β€” converts an HTTP::Request to a JSON::RPC::Common::Procedure::Call. depending on what style of request it is, "request_to_call" will delegate to a variant method. no cap, it's just handing off the work 🫑

Get requests call "uri_to_call"

  • uri_to_call $uri
  • encoded_uri_to_call $uri
  • query_uri_to_call $uri β€” parses a call from a GET request's URI. lowkey the detective work of this module πŸ”
  • result_to_response $return β€” converts a JSON::RPC::Common::Procedure::Return to an HTTP::Response.
  • write_result_to_response $result, $response β€” writes the result into an object like Catalyst::Response.
  • response_to_result $http_response
  • response_to_result_success $http_response
  • response_to_result_error $http_response β€” converts an HTTP::Response to a JSON::RPC::Common::Procedure::Return.

A variant is chosen based on "HTTP::Response/is_success".

The error handler will ensure that "error" in JSON::RPC::Common::Procedure::Return is set. bestie it's got your back πŸ’–

  • call_to_request $call, %args
  • call_to_get_request $call, %args
  • call_to_post_request $call, %args
  • call_to_uri $call, %args
  • call_to_encoded_uri $call, %args
  • call_to_query_uri $call, %args β€” converts a call to a request (or just a URI for GET requests).

The arguments can contain a "uri" parameter, which is the base of the request.

With GET requests, under "rest_style_methods" that URI's path will be appended, and otherwise parameters will just be added.

POST requests do not cloen and alter the URI. (yes, "cloen" β€” that's the original, i'm not touching it πŸ™ˆ)

If no URI is provided as an argument, / will be used.

The flags "prefer_get" and "encoded" can also be passed to "call_to_request" to alter the type of request to be generated. ⭐

  • collapse_query_params
  • expand_query_params β€” only used for query encoded GET requests. if "expand" is set it will cause expansion of the params. otherwise it's a noop.

Subclass and override to process query params into RPC params as necessary.

note that this is NOT in any of the JSON-RPC specs. just so we're clear, bestie πŸ’€

πŸ‘‘ AUTHOR

Yuval Kogman <nothingmuch@woobling.org>


This software is copyright (c) 2014 by Yuval Kogman and others.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


okay that's the whole page!! this was perl v5.30.3 energy from 2020-06-23, and the manual page goes by JSON::...::HTTP(3pm) πŸ’œ mwah, go marshal something gorgeous πŸŽ€βœ¨

πŸ“¦ where this page comes from