배달 차량 받기

이 문서에서는 gRPC 또는 REST를 사용하여 서버 환경에서 차량을 가져오는 방법을 설명합니다.

배송 차량 예시 가져오기

Java gRPC 라이브러리를 사용하여 차량을 가져오거나 REST를 사용할 수 있습니다.

자바

  static final String PROJECT_ID = "my-delivery-co-gcp-project";
  static final String VEHICLE_ID = "vehicle-8241890";

  DeliveryServiceBlockingStub deliveryService =
    DeliveryServiceGrpc.newBlockingStub(channel);

  // Vehicle request
  String name = "providers/" + PROJECT_ID + "/deliveryVehicles/" + VEHICLE_ID;
  GetDeliveryVehicleRequest getVehicleRequest = GetDeliveryVehicleRequest.newBuilder()  // No need for the header
      .setName(name)
      .build();

  try {
    DeliveryVehicle vehicle = deliveryService.getDeliveryVehicle(getVehicleRequest);
  } catch (StatusRuntimeException e) {
    Status s = e.getStatus();
    switch (s.getCode()) {
       case NOT_FOUND:
         break;
       case PERMISSION_DENIED:
         break;
    }
    return;
  }

REST

GET https://fleetengine.googleapis.com/v1/providers/<project_id>/deliveryVehicles/<vehicleId>

  # Set JWT, PROJECT_ID, and VEHICLE_ID in the local environment
  curl -H "Authorization: Bearer ${JWT}" \
    "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}"

다음 단계