client_code_generators 0.3.0

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

Converts HTTP requests into different languages of your choice, generating HTTP request code for the same language.

Client Code Generators

Converts HTTP requests into different languages of your choice, generating HTTP request code for the same language.

It is a package written in dart based on Postman's postman-code-generators package

How to use

language - The language of the code snippet to be generated. The list of supported languages can be found variant - The variant of the code snippet to be generated. The list of supported variants can be found request - The request object to be converted into code snippet options - The options object for the snippet generation callback - The callback function to be called after the snippet is generated


List of supported code generators:

languagevariant
Darthttp

List of supported options:

optiontypedescription
trimRequestBodybooleanWhether to trim request body fields
indentTypestringThe type of indentation to be used in the generated code snippet. Can be Tab or Space
indentCountnumberThe number of tabs or spaces to be used for indentation
requestTimeoutnumberThe timeout value for the request in millisecond
followRedirectbooleanWhether to follow redirects for the request
includeBoilerplatebooleanWhether to include boilerplate code for the snippet

List of supported body types:

typedescriptioncontent-type
rawRaw json dataapplication/json
urlencodedURL encoded form dataapplication/x-www-form-urlencoded
formdataMultipart form datamultipart/form-data
fileFile datamultipart/form-data
graphqlGraphQL queryapplication/graphql
noneNo bodynone

Getting Started

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  client_code_generators: ^0.3.0

You can install packages from the command line:

$ dart pub get

Usage

A simple usage example:

import 'package:client_code_generators/client_code_generators.dart';

main() {
  final request =
        Request('GET', 'https://jsonplaceholder.typicode.com/users');

    var options = {
      'trimRequestBody': true,
      'indentType': 'Space',
      'indentCount': 2,
      'requestTimeout': 0,
      'followRedirect': true,
      'includeBoilerplate': true
    };
    var language = 'Dart';
    var variant = 'http';
    
    convert(language, variant, request, options, (error, snippet) {
      print(snippet);
    });
}

Testing

$ dart test ./..

Contributing

Before opening an issue or pull request, please check the project's contribution documents.

Please read CONTRIBUTING.md for details about our code of conduct, and the process for submitting pull requests.

Support Donate

If you find this project useful, you can buy author a glass of juice 🧃

ko-fi

also a coffee ☕️

Buy Me A Coffee

will be very grateful to you for your support 😊.