
# Java {/* #java */}

Platform API belirteci oluşturmak ve `platform.proto` indirmek için [gRPC kılavuzuyla](/docs/tr/api/grpc) başlayın. İstemci sözleşmesi `java_package = "dev.reconstruct.platform.v1"` ayarını kullanır ve iletileri için ayrı Java sınıfları üretir. Bu örnek Gradle ve [gRPC Java protobuf eklentisini](https://github.com/grpc/grpc-java#generated-code) kullanır.

`platform.proto` dosyasını `src/main/proto/platform.proto` konumuna koyun. Bu `build.gradle` dosyasını ekleyin:

```groovy
plugins {
    id 'java'
    id 'application'
    id 'com.google.protobuf' version '0.9.5'
}

repositories { mavenCentral() }

def grpcVersion = '1.84.0'
dependencies {
    implementation "io.grpc:grpc-protobuf:${grpcVersion}"
    implementation "io.grpc:grpc-stub:${grpcVersion}"
    runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
    compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
}

protobuf {
    protoc { artifact = 'com.google.protobuf:protoc:3.25.8' }
    plugins {
        grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
    }
    generateProtoTasks {
        all()*.plugins { grpc {} }
    }
}

application { mainClass = 'dev.reconstruct.example.Main' }
```

Gradle projeyi derlerken ileti sınıflarını ve `PlatformServiceGrpc` üretir. Bunu `src/main/java/dev/reconstruct/example/Main.java` olarak kaydedin:

```java
package dev.reconstruct.example;

import dev.reconstruct.platform.v1.GetCatalogRequest;
import dev.reconstruct.platform.v1.ListCatalogsRequest;
import dev.reconstruct.platform.v1.PlatformServiceGrpc;
import io.grpc.Grpc;
import io.grpc.ManagedChannel;
import io.grpc.Metadata;
import io.grpc.TlsChannelCredentials;
import io.grpc.stub.MetadataUtils;
import java.util.concurrent.TimeUnit;

public final class Main {
    public static void main(String[] args) throws Exception {
        String token = System.getenv("CR_RECONSTRUCT_API_TOKEN");
        if (token == null || token.isBlank()) {
            throw new IllegalStateException("Set CR_RECONSTRUCT_API_TOKEN");
        }

        ManagedChannel channel = Grpc.newChannelBuilderForAddress(
            "reconstruct.dev", 443, TlsChannelCredentials.create()).build();
        try {
            Metadata headers = new Metadata();
            headers.put(Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER),
                "Bearer " + token);
            var client = PlatformServiceGrpc.newBlockingStub(channel)
                .withInterceptors(MetadataUtils.newAttachHeadersInterceptor(headers))
                .withDeadlineAfter(10, TimeUnit.SECONDS);

            var page = client.listCatalogs(ListCatalogsRequest.newBuilder().setPageSize(10).build());
            for (var catalog : page.getCatalogsList()) {
                var detail = client.getCatalog(GetCatalogRequest.newBuilder()
                    .setCatalogId(catalog.getCatalogId()).build());
                System.out.println(detail.getCatalogId() + ": " + detail.getDescription());
            }
        } finally {
            channel.shutdownNow();
        }
    }
}
```

`gradle run` çalıştırın (projenizde Gradle wrapper varsa `./gradlew run`). Yerel gRPC, `/api/v1` REST yolunu değil TLS authority adresini kullanır.
