Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Request and Response objects

Dmytro edited this page Jan 30, 2017 · 6 revisions

Class Request, with which you can to process requests

Available methods:

request.headers();       // the headers dictionary
request.method();        // string with req. method, "GET" for example 
request.uri;             // string with req. path, "/rest/hello" for example
request.exchange         // object which contains an all methods of com.sun.net.httpserver.HttpExchange standart package
request.cookie(), 
request.removeCookie(), 
request.cookies()         // working with cookies, more details in the next chapter
request.form()            // dictionary which contains a parsed body of x-www-form-urlencoded POST request
request.body              // a body of POST request in String format
request.query             // string with get parameters, if exists
request.queryPararms()    // parse a GET parameters to Map (v1.0.1+)
request.queryPararms("e") // return a String with value of GET parameter (v1.0.1+)

Class Response, with which you can send a response to client

Available methods:

response.type();         // set the content type of response data (take a 1 String-type parameter)
response.send();         // sending a String to client (take a 2 parameter (String data, int status))
response.sendFile();     // send a file to client, takes 1 String param. - path to file regarding the 
                         // paths specified in app.setStaticPath() method
response.render();       // render a freemarker template, takes a 2 params. 1 - path to .ftl template 
                         // regarding the paths specified in app.setStaticPath() method
response.redirect();     // redirect client to URL, which set as parameter of this method

Clone this wiki locally