Skip to content

Commit

Permalink
netdot: Add support for JSON on Netdot REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
vink78 committed Mar 11, 2021
1 parent d834662 commit 80755b2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/Netdot/REST.pm
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,11 @@ sub print_serialized {
$self->{request}->content_type(q{text/xml; charset=utf-8});

print $xml;
} elsif ( $mtype eq 'json' ){
use JSON;
$self->{request}->content_type(q{application/json; charset=utf-8});

print encode_json $data;
}
}

Expand Down Expand Up @@ -524,7 +529,10 @@ sub read_serialized {

if ( $mtype eq 'xml' ){
$self->_load_xml_lib();
$self->{xs}->XMLin($string);
return $self->{xs}->XMLin($string);
} elsif ( $mtype eq 'json' ){
use JSON;
return decode_json ($string);
}
}

Expand Down Expand Up @@ -557,6 +565,14 @@ sub check_accept_header{
}
last;
}
if ( $mtype eq 'text/json' || $mtype eq 'application/json' ){
$self->{media_type} = 'json';
if ( $parameters =~ /version=(\w+)/ ){
# This will be used in future versions of this API for backwards compatibility
$self->{version} = $1;
}
last;
}
}
# At this point, if we haven't found any supported media types, give up
unless ( $self->{media_type} ){
Expand Down

0 comments on commit 80755b2

Please sign in to comment.