Last active
November 21, 2017 22:50
-
-
Save MarcusLongmuir/4e9dd9c227ec5730e38907440c1678df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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