4

I am getting http error code 405 while calling the gRPC service from rest client.

I tried calling the delete method using the gRPC client, it is working fine (i.e. getting 200).

REST CLIENT

req, err = http.NewRequest("DELETE", fmt.Sprintf("%s%s", *address, "/v1/todo"), nil)
    resp, err = http.DefaultClient.Do(req)
    if err != nil {
        log.Fatalf("failed to call DeleteAll method: %v", err)
    }
    bodyBytes, err = ioutil.ReadAll(resp.Body)
    resp.Body.Close()
    if err != nil {
        body = fmt.Sprintf("failed read Delete response body: %v", err)
    } else {
        body = string(bodyBytes)
    }
    log.Printf("Delete response: Code=%d, Body=%s\n\n", resp.StatusCode, body)

gRPC Client

req6 := v1.DeleteAllRequest{
        Api: apiVersion,
    }
    res6, err := c.DeleteAll(ctx, &req6)
    if err != nil {
        log.Fatalf("Delete failed: %v", err)
    }
    log.Printf("Delete all result: <%+v>\n\n", res6)

Expected to get the delete function executed properly and get 200 http response.

  • 4
    The "normal" HTTP request isn't a valid gRPC call (not just the method, the path is wrong too). You should not handcraft HTTP requests for a gRPC service. Use the gRPC client libraries instead. – Peter May 15 '19 at 12:34

1 Answers1

0

Current Browsers dont support grpc natively. So I try to use a sidecar proxy from envoy (envoy by lyft) which acts as an interface for my grpc backend.

...
static_resources:
cluster:
- name: local_service
    connect_timeout: 0.25s
    type: strict_dns
    lb_policy: round_robin
    load_assignment:
      cluster_name: local_service
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: 127.0.0.1
                port_value: 8080
...

This is how i write a service in my envoy config, and this more details on this can be found on Envoy's Github Repository, they have multiple examples for better understanding the process.