Rest – Can PROTOBUF FIELD MASK can be applied to GRPC unique?

Let’s take this example from the official doc:

// Updates a book.
rpc UpdateBook (UpdateBookRequest) returns (Book) {
// Update maps to HTTP PATCH. Resource name is mapped to a URL path.
// Resource is contained in the HTTP request body.
option ( google.api.http) = {
// Note the URL template variable which captures the resource name of the
// book to update.
patch: "/v1/{book.name =shelves/*/books/*}"
body: "book"
};
}

message UpdateBookRequest {
// The book resource which replaces the resource on the server.
Book book = 1;

// The update mask applies to the resource. For the `FieldMask` definition,
// see https ://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask
FieldMask update_mask = 2;
}

If I don’t have a grpc gateway and only Using grpc, I can use the mask like this:

// Updates a book.
rpc UpdateBook(UpdateBookRequest ) returns (Book);

message UpdateBookRequest {
// The book resource which replaces the resource on the server.
Book book = 1;

// The update mask applies to the resource. For the `FieldMask` definition,
// see https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask
FieldMask update_mask = 2;
}

If so, how should this mask work-filter requests? Or apply it during db save and how it knows db…
So I am a bit confused about using it. In my own grpc example, I see that the mask does not filter requests.

According to the protobuf docs:

Field Masks in Update Operations
A field mask in update operations specifies which fields of the targeted resource are going to be updated. The API is required to only change the values ​​of the fields as specified in the mask and leave the others untouched. If a resource is passed in to describe the updated values, the API ignores the values ​​of all fields not covered by the mask.

When applying the field mask, it specifies A specific field updated in a gRPC request. Please remember that if you use it in an HTTP request, what you are collecting from me is what you are doing, it must be a PATCH request and not a PUT request.

For example , Suppose you have a declaration named Books, whose attributes are: title is a string, year_published is int32, and the author is the author. Declare that Author will use the field first_name as a string and last_name as a string. If you want to use author.first_name Field mask, you can only update the first_name field of the author in the book.

Please note that this is based on the protobufs document, I may completely misunderstand it, so please be patient.

< /p>

Let us take this example from the official doc:

// Updates a book.
rpc Upda teBook(UpdateBookRequest) returns (Book) {
// Update maps to HTTP PATCH. Resource name is mapped to a URL path.
// Resource is contained in the HTTP request body.
option (google.api.http) = {
// Note the URL template variable which captures the resource name of the
// book to update.
patch: "/v1/{book. name=shelves/*/books/*}"
body: "book"
};
}

message UpdateBookRequest {
// The book resource which replaces the resource on the server.
Book book = 1;

// The update mask applies to the resource. For the `FieldMask` definition,
// see https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask
FieldMask update_mask = 2;
}

If I don’t have a grpc gateway and Using only grpc, I can use the mask like this:

// Updates a book.
rpc UpdateBook(UpdateBookRequest) returns (Book);

message UpdateBookRequest {
// The book resource which replaces the r esource on the server.
Book book = 1;

// The update mask applies to the resource. For the `FieldMask` definition,
// see https:// developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask
FieldMask update_mask = 2;
}

If so, how should the mask work – Filter requests? Or apply it during db save and how it knows db…
So I am a bit confused about using it. In my own grpc example, I see that the mask does not filter requests.

According to the protobuf docs:

Field Masks in Update Operations
A field mask in update operations specifies which fields of the targeted resource are going to be updated. The API is required to only change the values ​​of the fields as specified in the mask and leave the others untouched. If a resource is passed in to describe the updated values, the API ignores the values ​​of all fields not covered by the mask.

When applying the field mask, it specifies the specific fields to be updated in the gRPC request. Remember , If you use it in an HTTP request, what I gather from me is what you are doing, it must be a PATCH request and not a PUT request.

For example, suppose you have a statement called Books, which The attributes are: title is a string, year_published is int32, and the author is the author. Declare that Author uses the field first_name as a string and last_name as a string. If you want to use the field mask of author.first_name, you can only update the author in the book first_name field.

Please note that this is based on the protobufs document, I may completely misunderstand it, so please be patient.

Leave a Comment

Your email address will not be published.