1# Concepts 2 3It is assumed that you are familiar with the gRPC concepts found here: https://grpc.io/docs/guides/concepts.html 4 5This page describes various concepts referred to within the gRPC-Web documentation. 6 7### Method Definition 8A method definition includes the service and method names, request and response types and whether the method is client-streaming and/or server-streaming. 9 10Definitions of the format used by `@improbable-eng/grpc-web` can be generated using the [`ts-protoc-gen`](https://github.com/improbable-eng/ts-protoc-gen) plugin for [protoc](https://github.com/google/protobuf). See [code generation](code-generation) for instructions. 11 12#### Example method definition: 13```javascript 14export namespace BookService { 15 export class GetBook { 16 static readonly methodName = "GetBook"; 17 static readonly service = BookService; 18 static readonly requestStream = false; 19 static readonly responseStream = false; 20 static readonly requestType = GetBookRequest; 21 static readonly responseType = Book; 22 } 23} 24``` 25 26### Metadata 27Metadata is a collection of key-value pairs sent by the client to the server and then from the server to the client both before the response (headers) and after the response (trailers). One use case for metadata is for sending authentication tokens from a client. 28 29`@improbable-eng/grpc-web` uses the [`js-browser-headers`](https://github.com/improbable-eng/js-browser-headers) library to provide a consistent implementation of the Headers class across browsers. The `BrowserHeaders` class from this library is aliased to `grpc.Metadata`. 30 31### Status Codes 32Upon completion a gRPC request will expose a status code indicating how the request ended. This status code can be provided by the server in the [Metadata](#metadata), but if the request failed or the server did not include a status code then the status code is determined by the client. 33 34`0 - OK` indicates that the request was completed successfully. 35 36#### `grpc.Code`: 37```javascript 380 OK 391 Canceled 402 Unknown 413 InvalidArgument 424 DeadlineExceeded 435 NotFound 446 AlreadyExists 457 PermissionDenied 468 ResourceExhausted 479 FailedPrecondition 4810 Aborted 4911 OutOfRange 5012 Unimplemented 5113 Internal 5214 Unavailable 5315 DataLoss 5416 Unauthenticated 55``` 56 57### Status Messages 58Alongside a status code, requests can include a message upon completion. This can be provided by the server in the [Metadata](#metadata), but if the request failed or the server did not include a status message then the status message is determined by the client and is intended to aid debugging. 59 60