---
name: "JSON::RPC::Common::Marshal::HTTP"
section: "3pm"
platform: "linux"
package: "libjson-rpc-common-perl"
version: "0.11-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/JSON::RPC::Common::Marshal::HTTP"
---

# JSON::RPC::Common::Marshal::HTTP(3pm)

Convert HTTP::Request and HTTP::Response to/from JSON::RPC::Common calls and returns.

## NAME

JSON::RPC::Common::Marshal::HTTP - Convert HTTP::Request and HTTP::Response to/from JSON::RPC::Common calls and returns.

## VERSION

version 0.11

## SYNOPSIS

```
        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 provides marshalling routines to convert calls and returns to and from HTTP::Request and HTTP::Response objects.

## ATTRIBUTES

- prefer\_get

  When encoding a call into a request, prefer GET.

  Not reccomended.

- rest\_style\_methods

  When encoding a GET request, use REST style URI formatting (the method is part of the path, not a parameter).

- prefer\_encoded\_get

  When set and a `"params"` param exists, decode it as Base 64 encoded JSON and use 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 and the JSON::RPC::Common version number.

- content\_type

  - accept\_content\_type

  - content\_types

  - accept\_content\_types

  When explicitly set these are the values of the `"Content-Type"` and `"Accept"` headers to set.

  Otherwise they will 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.

- expander

  An instance of CGI::Expand or a look alike to use for `"GET"` parameter expansion.

## METHODS

- request\_to\_call $http\_request

  - post\_request\_to\_call $http\_request

  - get\_request\_to\_call $http\_request

  Convert 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.

  Get requests call `"uri_to_call"`

- uri\_to\_call $uri

  - encoded\_uri\_to\_call $uri

  - query\_uri\_to\_call $uri

  Parse a call from a GET request's URI.

- result\_to\_response $return

  Convert a JSON::RPC::Common::Procedure::Return to an HTTP::Response.

- write\_result\_to\_response $result, $response

  Write 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

  Convert 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.

- 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

  Convert 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.

  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 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.

## AUTHOR

Yuval Kogman \<nothingmuch@woobling.org\>

## COPYRIGHT AND LICENSE

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.
