Skip to content

Instantly share code, notes, and snippets.

@MarcusLongmuir
Last active November 21, 2017 22:50
Show Gist options
  • Save MarcusLongmuir/4e9dd9c227ec5730e38907440c1678df to your computer and use it in GitHub Desktop.
Save MarcusLongmuir/4e9dd9c227ec5730e38907440c1678df to your computer and use it in GitHub Desktop.
import {grpc, BrowserHeaders} from "grpc-web-client";
// Import code-generated data structures.
import {BookService} from "../_proto/examplecom/library/book_service_pb_service";
import {QueryBooksRequest, Book, GetBookRequest} from "../_proto/examplecom/library/book_service_pb";
const queryBooksRequest = new QueryBooksRequest();
queryBooksRequest.setAuthorPrefix("Geor");
grpc.invoke(BookService.QueryBooks, {
request: queryBooksRequest,
host: "https://my.grpc.server.example.com",
onMessage: (message: Book) => {
console.log("got book: ", message.toObject());
},
onEnd: (code: grpc.Code, msg: string | undefined, trailers: BrowserHeaders) => {
if code == grpc.Code.OK {
console.log("all ok")
} else {
console.log("hit an error", code, msg, trailers);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment