... | ... | @@ -2,8 +2,11 @@ |
|
|
|
|
|
---
|
|
|
|
|
|
[[_TOC_]]
|
|
|
|
|
|
## Creating a server
|
|
|
---
|
|
|
|
|
|
# Creating a server
|
|
|
We shown how to create and start a web service on our [welcome page](Home). Sparkling analyzes the methods of the given handler object and uses Spark to add __both a GET and a POST__ endpoint for each method, together with parameter and return value conversion. Further, it __creates a documentation website__ for the handler object, listing all service methods available together with a generated Java interface for Java client instance creation. [Look here](GeneratedDocExample) for an example of a generated documentation website.
|
|
|
|
|
|
You have some possibilities to control server creation with Sparkling:
|
... | ... | @@ -17,10 +20,10 @@ You have some possibilities to control server creation with Sparkling: |
|
|
* Log __invocation statistics__ with `logInvocationStatsEveryNCalls=N`. The server will log every `N` method invocations the counts which method was called how often since the last server (re)start.
|
|
|
* You can __suppress__ that values of specified __parameters will be logged__ by Sparkling. Sometimes, in the case of an error, Sparkling will log parameter values for debugging reasons. If you e.g. for some reason have a password parameter, you don't want the passwords to appear in the logs. Suppress the logging by annotating the parameter with `@HideValueLogs` inside the handler method code.
|
|
|
|
|
|
### Spark as underlying micro framework
|
|
|
# Spark as underlying micro framework
|
|
|
Since Sparkling simply connects the Spark server to the handler methods with [Spark](http://sparkjava.com/), you can use __all Spark functionality__ furthermore. Nothing special. Add new requests before or after you add a handler with Sparkling, deal with https, and plenty of more. Look into the fantastic [Spark documentation](http://sparkjava.com/documentation) for all possibilities.
|
|
|
|
|
|
### Data conversion
|
|
|
# Data conversion
|
|
|
When you create the service http calls on your own, you have to deal with how Sparkling converts the parameter and return values. In general, primitive types will be offered inside the service API as-is (Strings, Numbers and Boolean). All other classes that are used as parameter or return values will be converted to and from JSON.
|
|
|
|
|
|
An example call would look like this:
|
... | ... | @@ -70,7 +73,7 @@ The following capabilities exist: |
|
|
|
|
|
|
|
|
|
|
|
### Java method parameter names
|
|
|
# Java method parameter names
|
|
|
Sparkling needs to know the parameter names of the handler object methods in order to offer according named parameters for the http GET and POST calls. Since the Java compiler does not provide them per default, we have to take care that Sparkling can get these names at server creation time.
|
|
|
|
|
|
Since Java version 8 the java compilers offers the command line option `-parameters`. With this flag enabled the compiler will write parameter name metadata into the created bytecode. These names are then available via the reflection API. Take care to enable this flag at compile time of your server.
|
... | ... | |