0.2.2 • Published 4 years ago

mdining-proto v0.2.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

mdining-proto

Build Status

Proto definitions for use with the michigan-dining-api service

The file mdining.proto defines the grpc service for michigan-dining-api and is the most important file for clients to use.

The remaining files define the proto messages used by the service

Language Support

Bazel \ Go \ Javascript/Node.js

Bazel

Add the following to your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

go_repository(
    name = "com_github_anders617_mdining_proto",
    importpath = "github.com/anders617/mdining-proto",
    sum = "h1:EIFfF2+iUhY/aRRxH3LqsDafKpDMp4tbEx7Wulb9th0=",
    version = "v0.0.9",
)

load("@com_github_anders617_mdining_proto//rules:rule_deps.bzl", "rule_dependencies")
rule_dependencies()
load("@com_github_anders617_mdining_proto//rules:proto_deps.bzl", "proto_dependencies")
proto_dependencies()
load("@com_github_anders617_mdining_proto//rules:go_deps.bzl", "go_dependencies")
go_dependencies()

Go

Go is supported through Bazel. You can reference the //proto:mdining_go_proto target like so:

go_library(
    name = "my_library",
    srcs = [
        "my_source.go"
    ],
    importpath = "github.com/my/import/path",
    deps = [
        "@com_github_anders617_mdining_proto//proto:mdining_go_proto",
    ],
)

In your Go code:

package main

import (
    "context"
    "fmt"

    pb "github.com/anders617/mdining-proto/proto/mdining"
    "google.golang.org/grpc"
)

func main() {
    address := "michigan-dining-api.herokuapp.com:80"
    fmt.Printf("Connecting to %s...", address)
    conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
    if err != nil {
        fmt.Printf("Could not dial %s: %s", address, err)
        return
    }
    defer conn.Close()
    fmt.Printf("Connected")

    // Create the MDiningClient
    client := pb.NewMDiningClient(conn)

    // Send a GetDiningHalls request
    diningHallsReply, err := client.GetDiningHalls(context.Background(), &pb.DiningHallsRequest{})

    if err != nil {
        fmt.Printf("Could not call GetDiningHalls: %s", err)
        return
    }
    fmt.Printf("DiningHallsReply: %v\n", diningHallsReply)
}

Javascript/Node.js

Download the npm package using npm:

npm install mdining-proto

or yarn:

yarn add mdining-proto

Then in your code you can import the proto types and client like so:

import { MDiningPromiseClient, DiningHallsRequest } from 'mdining-proto';

const client = new MDiningPromiseClient('https://michigan-dining-api.herokuapp.com');

client.getDiningHalls(new DiningHallsRequest())
    .then((diningHalls) => console.log(diningHalls))
    .catch((err) => console.log(err));

Development

Run the following command to build and publish the npm package

bazel run //:mdining_ts_proto_package.publish
0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.9

4 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago