Home > Back-end >  How to make a request to a URL with gRPC Transcoding Syntax with a standard POST request?
How to make a request to a URL with gRPC Transcoding Syntax with a standard POST request?

Time:12-08

I am attempting to use the endpoint https://firestore.googleapis.com/v1/{parent=projects/*}/databases with more data needed per the documentation on Google's docs.

The goal is to be able to make this request with a standard http utility such as cURL.

I have attempted performing the request manually through the GUI with the Chrome network tab open, and I saw a request being made: https://firebasedatabase.clients6.google.com/v1beta/projects/XXXXXXXXXX/locations/us-central1/instances?databaseId=my-database&validateOnly=true&alt=json&key=secretkey

Per trial and error on another endpoint, I have found that the key parameter can be replaced with a Bearer Auth token in the header. Other than that I am at a dead end.

CodePudding user response:

To make a request to a URL using gRPC Transcoding with a standard POST request, you will need to first make sure that the server you are sending the request to supports gRPC transcoding. Once you have confirmed that the server supports gRPC transcoding, you can use the grpc-web-text content-type to make your POST request. Here is an example of how you can make a POST request using gRPC transcoding:

POST /my_service HTTP/1.1
Host: example.com
Content-Type: application/grpc-web-text

{
  "method": "my_service.MyMethod",
  "parameters": {
    "my_param": "hello world"
  }
}

In this example, we are making a POST request to the /my_service endpoint on example.com, using the grpc-web-text content-type. The request body contains a JSON object with the name of the gRPC method we want to call (my_service.MyMethod) and the parameters we want to pass to the method (in this case, a single parameter called my_param with the value hello world).

  • Related