Configuration¶
This section covers all configuration options for you to customize the behavior of RESTArt APIs.
Options¶
Server¶
Option name | Default value | Description |
---|---|---|
SERVER_NAME | ‘’ | The server name (scheme + domain + port) |
Action mapping¶
Option name | Default value | Description |
---|---|---|
ACTION_MAP | {‘HEAD’: ‘head’, ‘TRACE’: ‘trace’, ‘GET’: ‘read’, ‘PUT’: ‘replace’, ‘POST’: ‘create’, ‘DELETE’: ‘delete’, ‘OPTIONS’: ‘options’, ‘PATCH’: ‘update’} | The mapping from request methods to resource actions, which is used to find the specified action to handle the request. |
Parsers and Renderers¶
Option name | Default value | Description |
---|---|---|
PARSER_CLASSES | (‘restart.parsers.JSONParser’, ‘restart.parsers.URLEncodedParser’, ‘restart.parsers.MultiPartParser’) | The default Parser classes. |
RENDERER_CLASSES | (‘restart.renderers.JSONRenderer’,) | The default Renderer classes. |
Logger¶
Option name | Default value | Description |
---|---|---|
LOGGER_ENABLED | True | Enable or disable the global logger. |
LOGGER_METHODS | (‘GET’, ‘POST’, ‘PUT’, ‘PATCH’, ‘DELETE’) | A sequence of HTTP methods whose messages should be logged. |
LOGGER_LEVEL | ‘INFO’ | The logging level. |
LOGGER_FORMAT | ‘%(asctime)s.%(msecs)03d %(name)-10s %(levelname)-8s %(message)s’ | The logging format for strings. |
LOGGER_DATE_FORMAT | ‘%Y-%m-%d %H:%M:%S’ | The logging format for date/time. |
Middlewares¶
Option name | Default value | Description |
---|---|---|
MIDDLEWARE_CLASSES | () | The middleware classes used to alter RESTArt’s requests and responses. |
Customization¶
You can customize all of the above configuraion options by following the steps below:
Create a Python module to set your preferred values:
$ vi restart_config.py LOGGER_METHODS = ['POST', 'PUT', 'PATCH'] LOGGER_LEVEL = 'DEBUG'
Set the environment variable
RESTART_CONFIG_MODULE
to the Python path of the above module:$ export RESTART_CONFIG_MODULE=pythonpath.to.restart_config
That’s all. Then, while your API is running, messages with DEBUG (or higher) level will be logged for any request whose HTTP method is POST, PUT or PATCH.