Skip to content

first light

Roland Schuller edited this page Apr 4, 2019 · 1 revision

Lets make a first simple application

Create the Server and let it run on Port 300

RestHttpServer server=RestHttpServer.Start(3000); 

What about an index page which tells some imformation about the api and what it is for?

server.enableIndex("TestProg", "1.0", "IT-Open", "office@it-open.at"); 

If anything goes wrong in the code display a good Exception page

server.enableExceptionHandling();

If you request a page which is not there.

server.enableNotFoundHandling();

Give me a detail about the structure of all endpoints.

server.enableStructure("structure",null);

No just an urllist

server.enableRestUrlList("urls",null);

A bit more information: How about an REST Api Doc

server.enableRestDoc("doc",null);

Endpoint

Lets start and make our own Endpoint

server.getRootEndpoint().addRestEndpoint(new RestEndpoint("test"){
                @Override
                public void Call(Conversion conversion, Map<String,String> UrlParameter) {
                    conversion.getResponse().setData("Super");
                }
            
            });

Call it with http://localhost:3000/test and you will get

{
   "code":200,
   "message":"The request sent by the client was successful.",
   "generationMsSeconds":13.487463,
   "data":"Super"
}

Whatever Object you give into conversion.getResponse().setData( Pojo-Object ); will be converted to an JSON Object. All getters will be interpreted.

SubPath

RestPath path=server.getRootEndpoint().addSubPath(new RestPath("sub"));
// or short Form
RestPath path=server.getRootEndpoint().addSubPath("sub");

//Later get the Path
RestPath path=server.getPath("/sub");

path.addRestEndpoint(RestEndpoint ep);
Clone this wiki locally