Running
To run the software as a standalone webserver:
java -jar jars/json-httpd.jar
The webserver will look in the working directory for a folder namned webroot for its contents
Creating the webserver
// Create server at port 8080.
httpd = new HTTPServer(8080, 20);
// Add an service.
httpd.addService(new ExampleService());
// Start the server
httpd.start();
Writing a JSON-RPC Service
- Create a class.
- Create a method that takes arguments of type String, int, long, float or doble, return value should be a JSON formated string.
- Add the @JsonServiceMethod annotation to the method.
- Write the code and generate a JSON formated return value with the JSONWriter class. (For more info about JSONWriter check http://www.stringtree.org/stringtree-json.html).
Example JSON-RPC Service:
public class ExampleService
{
@JsonServiceMethod
public String log(double log)
{
JSONWriter writer = new JSONWriter();
return writer.write(Math.log10(log));
}
}