Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add A YAML Body Serializer? #49

Open
CurtTilmes opened this issue Sep 12, 2018 · 2 comments
Open

Add A YAML Body Serializer? #49

CurtTilmes opened this issue Sep 12, 2018 · 2 comments

Comments

@CurtTilmes
Copy link

CurtTilmes commented Sep 12, 2018

Something like:

use Cro::HTTP::BodySerializers;
use YAML;

class Cro::HTTP::BodySerializer::YAML does Cro::HTTP::BodySerializer {
    method is-applicable(Cro::HTTP::Message $message, $body --> Bool)
    {
        with $message.content-type {
            (.type eq 'text' && .subtype eq 'x-yaml') &&
                ($body ~~ Map || $body ~~ List)
        }
        else {
            False
        }
    }

    method serialize(Cro::HTTP::Message $message, $body --> Supply)
    {
        my $yaml = yaml.dump($body).encode('utf-8');
        self!set-content-length($message, $yaml.bytes);
        supply { emit $yaml }
    }
}

Note, I used YAML instead of YAMLish... I realize the dependency hell this leads to, so I suspect you won't want it in this repository. (Could make a Cro::HTTP::BodySerializer::YAMLish too..)

Where is the right place for this? Could you put it in a separate croservices repository? Should I simply release it separately to ecosystem through CPAN myself?

@jnthn
Copy link
Member

jnthn commented Sep 15, 2018

Probably a module that provides both a YAML body parser and body serializer would be good, yes. I agree it doesn't belong in core. Maybe Cro::HTTP::Body::YAML is a decent distribution name, and I'd be good with creating a repo under croservices and having it mentioned in the Cro docs.

@CurtTilmes
Copy link
Author

I think it is pretty straight forward to clone from JSON and do the YAML parse/dump, but if you don't want to take the time, if you create a mostly empty Cro::HTTP::Body::YAML croservices repo, I'll fork it and give you a PR with some basics and tests to start from.

YAMLish is kind of fundamentally broken, but you could do the same with Cro::HTTP::Body::YAMLish and I'll do that one too.

YAML is kind of broken too, but it is getting there.

I love YAML, but it isn't very mature for Perl 6 yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants