Skip to content

Client Emitters

How to Use Emitters to Generate HTTP Clients from TypeSpec

Introduction

This guide will walk you through the process of using different client emitters (JavaScript, Python, Java, .NET) to generate HTTP clients from TypeSpec. Please note that all client emitters are currently in preview and are subject to changes in future versions.

By following this guide, you will learn:

  1. How to set up client emitters in package.json.
  2. Update the client emitter configurations in tspconfig.yaml.
  3. How to generate HTTP clients for each specific programming language.

Location of All Client Emitters

The client emitters are defined in the package.json file within your project.

Emitter NameLanguageVersion
@azure-tools/typespec-tsJavaScript
@typespec/http-client-pythonPython
@typespec/http-client-javaJava
@typespec/http-client-csharp.NET

Below is an example of the package.json snippet where client emitters are defined:

"dependencies": {
"@typespec/http-client-csharp": "^0.1.9-alpha.20250113.2",
"@typespec/http-client-java": "^0.1.9",
"@typespec/http-client-python": "^0.6.6",
"@azure-tools/typespec-ts": "^0.38.1",
}

Client Emitter Settings

This part provides an overview of the common and language-specific settings for each client emitter. These settings are stored in the tspconfig.yaml file.

Common Configuration Options

The below option applies to all client emitters.

  • emitter-output-dir: Defines where the generated SDK files will be stored.

JavaScript Client Emitter Settings

JavaScript generally requires minimal configuration. However, it is recommended to provide packageDetails for package metadata, which is used in package.json and README.md files.

packageDetails

Provide the metadata for package.json, README.md information.

PropertyDescription
namePackage name used in package.json
descriptionPackage description used in package.json file
versionDetailed version for your package, the default value is 1.0.0-beta.1

Example configuration:

packageDetails:
name: "${your_package_name}"
version: 1.0.0

Java Client Emitter Settings

Prerequisites

Before using the Java client emitter, ensure the following dependencies are installed:

  • Java 17 or later - Download here
    (Verify installation with java --version)
  • Maven - Download here
    (Verify installation with mvn --version)

.NET Client Emitter Settings

(Details to be added by .NET contributors)

Running Language-Specific Emitters in CLI

  1. Ensure that your package.json file is correctly configured to include the necessary dependencies for running the emitters

  2. Update the tspconfig.yaml file for properly configured for the language-specific emitter.

    emit:
    - "@typespec/http-client-csharp"
    - "@typespec/http-client-java"
    - "@typespec/http-client-python"
    - "@azure-tools/typespec-ts"
    options:
    "@typespec/http-client-csharp":
    emitter-output-dir: "{project-root}/clients/dotnet"
    "@typespec/http-client-java":
    emitter-output-dir: "{project-root}/clients/java"
    "@typespec/http-client-python":
    emitter-output-dir: "{project-root}/clients/python"
    "@azure-tools/typespec-ts":
    emitter-output-dir: "{project-root}/clients/javascript"
    packageDetails:
    name: "${your_package_name}"
    version: 1.0.0
  3. Once the package.json and tspconfig.yaml files are updated, you need to install all required dependencies by running the following command in the project root:

    Terminal window
    tsp install
  4. Run the emitter to compile your TypeScript code into the desired language. Use the following command to trigger the emitter and compile your project:

    Terminal window
    tsp compile {path to main.tsp}/main.tsp

Disclaimer