# codegen-csharp-restsharp

> Converts Postman-SDK Request into code snippet for Csharp-RestSharp.

#### Prerequisite
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.

## Using the Module
The module will expose an object which will have property `convert` which is the function for converting the Postman-SDK request to Csharp-RestSharp code snippetand `getOptions` function which returns an array of supported options.

### convert function
Convert function will take three parameters
* `request`- Postman-SDK Request object

* `options`- options is an object which can have following properties
    * `indentType`- Character used for indentation
    * `indentCount`- The number of indentation characters to add per code level
    * `includeBoilerplate` - Include class definition and import statements in snippet
    * `requestTimeout` : The number of milliseconds the request should wait for a response before timing out (use 0 for infinity)
    * `trimRequestBody` : Trim request body fields
    * `followRedirect` : Automatically follow HTTP redirects

* `callback`- callback function with first parameter as error and second parameter as string for code snippet

##### Example:
```js
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
});
```
### getOptions function

This function returns a list of options supported by this codegen.

```js
var options = getOptions();

console.log(options);
// output
// [
//     {
//         name: 'Include boilerplate',
//         id: 'includeBoilerplate',
//         type: 'boolean',
//         default: false,
//         description: 'Include class definition and import statements in snippet'
//       },
//       {
//         name: 'Set indentation count',
//         id: 'indentCount',
//         type: 'positiveInteger',
//         default: 2,
//         description: 'Set the number of indentation characters to add per code level'
//       },
//       ...
// ]
```
### Guideline for using generated snippet

* 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-type` needs to be specified in order to add body to the request. So if no `content-type` is specified then `text/plain` will be used as default. **In case of `multipart/formdata` `content-type` is generated by snippet itself**.

* This module doesn't support cookies.
