Converts Postman-SDK Request into code snippet for Java-OkHttp.
To run Code-Gen, ensure that you have NodeJS >= v6. A copy of the NodeJS installable can be downloaded from https://nodejs.org/en/download/package-manager.
The module will expose an object which will have property convert which is the function for converting the Postman-SDK request to java-okhttp code snippet and getOptions function which returns an array of supported options.
Convert function will take three parameters
-
request- Postman-SDK Request object -
options- options is an object which can have following propertiesindentType- string representing type of indentation for code snippet. eg: 'Space', 'Tab'indentCount- positiveInteger representing count of indentation required.includeBoilerplate- boolean representing whether to include class definition in code snippetrequestTimeout: Integer denoting time after which the request will bail out in milli-secondstrimRequestBody: Trim request body fieldsfollowRedirect: Boolean denoting whether to redirect a request
-
callback- callback function with first parameter as error and second parameter as string for code snippet
var request = new sdk.Request('www.google.com'), //using postman sdk to create request
options = {
indentType: 'Space',
indentCount: 2,
includeBoilerplate: false
};
convert(request, options, function(error, snippet) {
if (error) {
// handle error
}
// handle snippet
});This function returns a list of options supported by this codegen.
var options = getOptions();
console.log(options);
// output
// [
// {
// name: 'Set indentation count',
// id: 'indentCount',
// type: 'positiveInteger',
// default: 2,
// description: 'Set the number of indentation characters to add per code level'
// },
// ...
// ]-
Generated snippet requires dependencies okhttp3 and okio to compile and run
-
Generated snippet uses
.method(nameOfMethod, body)fromRequestclass to form HTTP request. If themethoddoesn't require body then the value ofbodywill benull. -
Generated snippet uses
MultipartBody.Builder()whenmultipart/formdatais used otherwise it usesRequestBody.create()in order to add body to request. -
Since Postman-SDK Request object doesn't provide complete path of the file, it needs to be manually inserted in case of uploading a file.
-
content-typeneeds to be specified in order to add body to the request. So if nocontent-typeis specified thentext/plainwill be used as default. In case ofmultipart/formdatacontent-typeis generated by snippet itself. -
This module doesn't support cookies.