Editor
how to test api in ApiHug Api design Copilot.
Test
tabPrior
change request or Post
change responsegroovy
SyntaxPrior
request manipulate before send, Post
response manipulaeCommon Part:
Method | Description | Comment |
---|---|---|
String getHeader(String key) | get header | both request/response |
List<String> getHeaders(String key) | get header as list | both request/response |
List<String> getHeaderKeys() | get header key list | both request/response |
Method | Description | Comment |
---|---|---|
String getUrl() | Get URL | - |
void setUrl(String url) | Overwrite URL | - |
String getParameter(String name) | Get Parameter | If list only first return |
void setParameter(String name, String value) | Set Parameter | Overwrite exist |
void setParameters(Map<String, String> parameters) | Set Parameter Map | - |
void addParameter(String name, String value) | Add Parameter | - |
void removeParameter(String name) | Delete Parameter | - |
void setFormData(String name, String value) | Set Form Data | - |
void setHeader(String name, String value) | Set header | - |
void addHeader(String name, String value) | Add header | - |
void removeHeader(String name) | Remove header | - |
byte[] getRequestBody() | Get request body | - |
void setRequestBody(String payload) | Set request body | String |
void setRequestBody(byte[] payload) | Set request body | byte |
void setRequestBody(InputStream input) | Set request body | Stream |
Map<String, List<String>> getParameterMap() | Get all parameter | - |
List<String> getParameterValues(String name) | Get all parameter name | - |
void setCookie(String cookie) | Set cookie | - |
Method | Description | Comment |
---|---|---|
String getResponseBody() | Get response body | String |
int getCode() | Get http code | - |
String getCookie(String name) | Get cookie by name | - |
String getCookie() | Get cookie | Entire cookie as String |
Debug log to IDEA console:
Method | Description | Comment |
---|---|---|
void clear() | clear | - |
void warn(final String message) | warn | - |
void info(final String message) | info | - |
void debug(final String message) | debug | - |
void error(final String message) | error | - |
It can be used to update the current runtime environment parameters or variables based on the returned information.
Method | Description | Comment |
---|---|---|
void updateGlobalVariable(String name, Object value) | Overwrite global variable | - |
void updateGlobalParameter(String name, Object value) | Overwrite global parameter | - |
void updateEnvVariable(String name, Object value) | Overwrite current env variable | - |
void updateEnvParameter(String name, Object value) | Overwrite current env parameter | - |
Pay attention for those tips:
dummy
object is meant to assist you during the design phase. It will be automatically adjusted at runtime, so please do not touch it.// Place your logic here
indicates the starting point for your code.gradle build
for the project. Otherwise, the context may not be accessible, and code suggestions may not work properly. This is a one-time task.;
) at the end.logger
to output information instead of using System.out
.Context included:
request
, original requestlogger
, logger to track the output
import hope.common.script.HTTPRequest
import hope.common.script.LoggerAdapter
/************************************************************************
* 1. Do not touch code below, it will be injected at runtime
* 2. Fellow the groovy syntax, Java syntax almost can work
************************************************************************/
HTTPRequest request = HTTPRequest.DUMMY
LoggerAdapter logger = LoggerAdapter.DUMMY
/*************************************************************************/
// Place your logic here
headerKey = request.getHeader("key");
if (headerKey != null) {
logger.warn("we has header value $headerKey")
} else {
logger.warn("we has no header value set")
}
//request.setHeader("key","value");
Context included:
response
, response objectlogger
, logger to track outputruntime
, interface to update runtime environment
import hope.common.script.HTTPResponse
import hope.common.script.LoggerAdapter
import hope.common.script.RuntimeContext
/************************************************************************
* 1. Do not touch code below, it will be injected at runtime
* 2. Fellow the groovy syntax, Java syntax almost can work
************************************************************************/
HTTPResponse response = HTTPResponse.DUMMY
LoggerAdapter logger = LoggerAdapter.DUMMY
RuntimeContext runtime = RuntimeContext.DUMMY
/*************************************************************************/
// Place your logic here
response.getHeader("key");