-
Notifications
You must be signed in to change notification settings - Fork 3
Response classes
Christian Metz edited this page Jul 13, 2013
·
2 revisions
Collection of response classes for TinyServer.
- File response
- HTML response
- JSON response
It's simple to create your own response class for a missing format.
Here is a template that helps you to get started.
- Create a new class that extends
ResponseFormat
. - Add a constructor that defines your MIME type, by calling
super(<MIME type>)
. - Implement the abstract
success
method and override all other that are required.- use enum
STATUS_CODE
to get response codes and messages:
STATUS_CODE.<type>.<method>
➜STATUS_CODE.SUCCESS.getCode();
- Available types:
SUCCESS
,FORBIDDEN
,NOT_FOUND
,ERROR
- Available methods:
getCode()
,getHeader()
,getDesc()
- use enum
- Define the parameter type of the
success()
method, in a generic:
class MyResponse extends ResponseFormat<Type>