RDF::Server::Formatter::JSON - Work with JSON documents


RDF-Server documentation Contained in the RDF-Server distribution.

Index


Code Index:

NAME

Top

RDF::Server::Formatter::JSON - Work with JSON documents

SYNOPSIS

Top

 package My::Server;

 protocol 'HTTP';
 interface 'REST';
 semantic 'Atom';

 format json => 'JSON';

DESCRIPTION

Top

Formats documents as JSON for easy use by JavaScript programs. This formatter is currently for read-only operations and does not support submitting JSON to the server.

METHODS

Top

All methods that return a document also return a mime type of application/json as the first element of a two-element array. The document is the second element.

wants_rdf

Returns false. The JSON formatter works with perl data structures instead of RDF documents.

resource

This will return the resource data encoded as JSON.

to_rdf

This will accept JSON and return RDF. This method is not yet implemented. This method does not return a mime type.

feed

Returns a JSON representation of a list of resources.

category

Returns a JSON representation of a document following the semantics of an atom:category document.

collection

Returns a JSON representation of a document following the semantics of an app:collection document: a list of categories.

workspace

Returns a JSON representation of a document following the semantics of an app:workspace document: a list of collections.

service

Returns a JSON representation of a document following the semantics of an app:service document: a list of workspaces.

AUTHOR

Top

James Smith, <jsmith@cpan.org>

LICENSE

Top

Copyright (c) 2008 Texas A&M University.

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.


RDF-Server documentation Contained in the RDF-Server distribution.

package RDF::Server::Formatter::JSON;

use Moose;
with 'RDF::Server::Formatter';

use MooseX::Types::Moose qw(ArrayRef Str);
use RDF::Server::Constants qw(:ns);
use JSON::Any;
use RDF::Server::Exception;

# we need a way to communicate the mime type

our $JSON = JSON::Any -> new;

sub wants_rdf { 0 }

###
# Entry / Resource formatting
###

sub resource { return ( 'application/json', $JSON -> encode($_[1]) ); }

sub to_rdf {  
    my($self, $content) = @_;

    throw RDF::Server::Exception::BadRequest
       Content => 'Not implemented';

#    my $data = $JSON -> decode( $content );

    # now make RDF from the data structure
}

###
# List formatting
###

sub feed {
    my($self, @list) = @_;

    return( 'application/json', $JSON -> encode( \@list ) );
}

sub category {
    my($self, %c) = @_;

    return( 'application/json', $JSON -> encode( \%c ) );
}

sub collection {
    my($self, %c) = @_;

    return( 'application/json', $JSON -> encode( \%c ) );
}

sub workspace {
    my($self, %c) = @_;

    return( 'application/json', $JSON -> encode( \%c ) );
}

sub service {
    my($self, %c) = @_;

    return( 'application/json', $JSON -> encode( \%c ) );
}

1;

__END__