GithubHelp home page GithubHelp logo

renovate-tests / gapic-generator-typescript Goto Github PK

View Code? Open in Web Editor NEW

This project forked from googleapis/gapic-generator-typescript

0.0 0.0 0.0 598 KB

Generate Typescript API client libraries from Protocol Buffers.

License: Apache License 2.0

HTML 30.85% JavaScript 13.17% TypeScript 53.68% Shell 1.69% Dockerfile 0.60%

gapic-generator-typescript's Introduction

API Client Generator for TypeScript

Background

This tool is a TypeScript client library generator for network APIs specified by protocol buffers (including, but not limited to, client libraries for Google Cloud APIs).

It can be used for any API that uses protocol buffers and follows the conventions described in API Improvement Proposals.

Getting started

The Showcase API is a good API to play with if you want to start generating your own client libraries. It has several services, we'll use Echo service as an example.

Proto definitions for Echo service

Take a look at echo.proto that describes a simple network service.

Download the proto files locally (the following examples work in Linux or macOS):

$ curl -L https://github.com/googleapis/gapic-showcase/releases/download/v0.6.1/gapic-showcase-0.6.1-protos.tar.gz | tar xz

Run the generator to generate TypeScript libraries

The easiest way to get started is to use our Docker image:

$ mkdir showcase-typescript
$ docker run --rm \
  --mount type=bind,source=`pwd`/google/showcase/v1beta1,destination=/in/google/showcase/v1beta1,readonly \
  --mount type=bind,source=`pwd`/showcase-typescript,destination=/out \
  gcr.io/gapic-images/gapic-generator-typescript:latest

The resulting files are in showcase-typescript folder:

$ cd showcase-typescript
$ npm install  # install dependencies
$ npm run fix  # format the code
$ npm test     # run unit tests

Start the server that serves an API

Download the pre-compiled binary for your operating system from the Releases page and start the binary, or just use Docker:

# in another window
$ docker run -p 7469:7469/tcp -p 7469:7469/udp -p 1337:1337/tcp --rm gcr.io/gapic-images/gapic-showcase:0.6.1

Write your JavaScript or TypeScript code that uses the server!

Assuming you have Node.js installed and node binary in your path:

$ node
Welcome to Node.js v12.1.0.
Type ".help" for more information.
> const showcase = require('.')  // assuming you're in showcase-typescript
undefined
> const client = new showcase.EchoClient({ sslCreds: require('@grpc/grpc-js').credentials.createInsecure() })
undefined
> client.echo({ content: 'hello world!' }).then(console.log)
Promise { <pending> }
> [ { content: 'hello world!' }, undefined, undefined ]

Want to know more?

Read the AIPs or just create an issue in this repository if you have questions! We support some cool things such as streaming RPCs, auto-pagination for certain types of RPCs, and long running operations.

Disclaimer

This is not an official Google product.

gapic-generator-typescript's People

Contributors

alexander-fenster avatar justinbeckwith avatar renovate-bot avatar xiaozhenliu-gg5 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.