NAME
MyApp::REST - Example of REST server
VERSION
Version 1.00
SYNOPSIS
PerlOptions +GlobalRequest
PerlModule MyApp::REST
<Location /foo>
PerlInitHandler MyApp::REST
PerlSetVar Debug on
PerlSetVar Location foo
</Location>
DESCRIPTION
The module demonstrate various examples of how RAMST handlers work.
METHODS
Base methods
handler
See "handler" in MPMinus::REST
hInit
RAMST METHODS
RAMST methods
GET /foo
curl -v --raw -H "Accept: application/json" http://rest.localhost/foo?bar=123
> GET /foo?bar=123 HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: application/json
>
< HTTP/1.1 200 OK
< Date: Fri, 12 Apr 2019 11:42:18 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Content-Length: 623
< Content-Type: application/json
<
{
"debug_time" : "0.517",
"code" : 200,
"location" : "foo",
"uri" : "/foo",
"name" : "getIndex",
"servers" : [
"MyApp-REST#/",
"MyApp-REST#foo"
],
"hostname" : "mnslpt",
"startedfmt" : "04/12/19 14:42:18 MSK",
"foo_attr" : "blah-blah-blah",
"server_status" : 1,
"stamp" : "[5153] MyApp::REST at Fri Apr 12 14:42:18 2019",
"usr" : {
"bar" : "123"
},
"key" : "GET#/#default",
"error" : "",
"dvars" : {
"testvalue" : "",
"debug" : "on",
"location" : "foo"
},
"remote_addr" : "127.0.0.1",
"path" : "/",
"started" : 1555069338
}
Examples:
curl -v --raw http://rest.localhost/foo
curl -v --raw -H "Accept: application/json" http://rest.localhost/foo
curl -v --raw -H "Accept: application/xml" http://rest.localhost/foo
curl -v --raw -H "Accept: application/x-yaml" http://rest.localhost/foo
GET /foo?act=error
curl -v --raw -H "Accept: application/json" "http://rest.localhost/foo?act=error"
> GET /foo?act=error HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: application/json
>
< HTTP/1.1 500 Internal Server Error
< Date: Fri, 12 Apr 2019 11:47:35 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Content-length: 90
< Connection: close
< Content-Type: application/json
<
{
"error" : {
"code" : 500,
"message" : "getIndexError test error!"
}
}
GET /foo?act=custom
curl -v --raw -H "Accept: application/json" "http://rest.localhost/foo?act=custom"
> GET /foo?act=custom HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: application/json
>
< HTTP/1.1 503 Service Unavailable
< Date: Fri, 12 Apr 2019 11:50:17 GMT
< Server: Apache/2.4.18 (Ubuntu)
< X-Test-Header: Foo
< Content-Length: 78
< Connection: close
< Content-Type: application/json
<
{
"customerror" : "Test custom error",
"name" : "getIndexCustomError"
}
GET /foo?act=custom
curl -v --raw -H "Accept: application/json" http://rest.localhost/foo/deep/user/123
> GET /foo/deep/user/123 HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: application/json
>
< HTTP/1.1 200 OK
< Date: Fri, 12 Apr 2019 12:11:54 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Content-Length: 112
< Content-Type: application/json
<
{
"path" : "/deep/user/123",
"location" : "foo",
"uri" : "/foo/deep/user/123",
"name" : "getDeep"
}
POST /foo
curl -X POST -v -d '{"object": "list_services", "params": {}}' --raw -H "Content-Type: application/json" http://rest.localhost/foo
> POST /foo HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 41
>
* upload completely sent off: 41 out of 41 bytes
< HTTP/1.1 200 OK
< Date: Fri, 12 Apr 2019 11:51:41 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Content-Length: 195
< Content-Type: application/json
<
{
"key" : "POST#/#default",
"error" : "",
"code" : 200,
"server_status" : 1,
"input_data" : {
"params" : {},
"object" : "list_services"
},
"name" : "postIndex"
}
GET /foo/null
curl -v --raw -H "Accept: application/json" "http://rest.localhost/foo/null"
> GET /foo/null HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: application/json
>
< HTTP/1.1 204 No Content
< Date: Fri, 12 Apr 2019 11:52:43 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Content-Type: text/plain; charset=utf-8
<
GET /foo/test
curl -v --raw -H "Accept: application/json" "http://rest.localhost/foo/test"
> GET /foo/test HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: application/json
>
< HTTP/1.1 200 OK
< Date: Fri, 12 Apr 2019 11:53:27 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Content-Length: 49
< Content-Type: application/json
<
{
"uri" : "foo/test",
"name" : "getTest"
}
PUT /foo/test
curl -v --raw -X PUT -H "Content-Type: application/json" -d '{"foo":"bar"}' "http://rest.localhost/foo/test"
> PUT /foo/test HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 13
>
* upload completely sent off: 13 out of 13 bytes
< HTTP/1.1 201 Created
< Date: Fri, 12 Apr 2019 11:54:40 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Location: foo/test
< Content-Length: 95
< Content-Type: application/json
<
{
"uri" : "foo/test",
"input_data" : {
"foo" : "bar"
},
"name" : "putTest"
}
POST /foo/test
curl -v --raw -H "Content-Type: application/json" -d '{"foo":"bar"}' "http://rest.localhost/foo/test"
> POST /foo/test HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 13
>
* upload completely sent off: 13 out of 13 bytes
< HTTP/1.1 201 Created
< Date: Fri, 12 Apr 2019 11:55:56 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Location: foo/test
< Content-Length: 96
< Content-Type: application/json
<
{
"uri" : "foo/test",
"input_data" : {
"foo" : "bar"
},
"name" : "postTest"
}
PATCH /foo/test
curl -v --raw -X PATCH -H "Content-Type: application/json" -d '{"foo":"bar"}' "http://rest.localhost/foo/test"
> PATCH /foo/test HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 13
>
* upload completely sent off: 13 out of 13 bytes
< HTTP/1.1 200 OK
< Date: Fri, 12 Apr 2019 11:57:23 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Content-Length: 97
< Content-Type: application/json
<
{
"uri" : "foo/test",
"input_data" : {
"foo" : "bar"
},
"name" : "patchTest"
}
PATCH /foo/test
curl -v --raw -X DELETE http://rest.localhost/foo/test
> DELETE /foo/test HTTP/1.1
> Host: rest.localhost
> User-Agent: curl/7.50.1
> Accept: */*
>
< HTTP/1.1 204 No Content
< Date: Fri, 12 Apr 2019 12:03:07 GMT
< Server: Apache/2.4.18 (Ubuntu)
<
DEPENDENCIES
mod_perl2
, MPMinus, MPMinus::REST
TO DO
See TODO
file
BUGS
* none noted
SEE ALSO
AUTHOR
Serż Minus (Sergey Lepenkov) http://www.serzik.com <abalama@cpan.org>
COPYRIGHT
Copyright (C) 1998-2019 D&D Corporation. All Rights Reserved
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See LICENSE
file and https://dev.perl.org/licenses/