MyApp::REST - Example of REST server
Version 1.00
PerlOptions +GlobalRequest PerlModule MyApp::REST <Location /foo> PerlInitHandler MyApp::REST PerlSetVar Debug on PerlSetVar Location foo </Location>
The module demonstrate various examples of how RAMST handlers work.
Base methods
See "handler" in MPMinus::REST
See "hInit" in MPMinus::REST
RAMST methods
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
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!" } }
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" }
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" }
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" }
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 <
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" }
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" }
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" }
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" }
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) <
mod_perl2, MPMinus, MPMinus::REST
mod_perl2
See TODO file
TODO
* none noted
MPMinus, MPMinus::REST
Serż Minus (Sergey Lepenkov) http://www.serzik.com <abalama@cpan.org>
Copyright (C) 1998-2019 D&D Corporation. All Rights Reserved
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/
LICENSE
To install MPMinus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MPMinus
CPAN shell
perl -MCPAN -e shell install MPMinus
For more information on module installation, please visit the detailed CPAN module installation guide.