# README
mdining-proto
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
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:EqFtsULZ1MWoAAJKotZvMwR351syYg9eiDdBm1pBf78=",
version = "v0.2.2",
)
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
# Packages
No description provided by the author