package com.example.myapp;
import com.unkey.unkeysdk.dto.KeyCreateResponse;
import com.unkey.unkeysdk.dto.KeyCreateRequest;
@RestController
public class APIController {
private static IKeyService keyService = new KeyService();
@PostMapping("/createKey")
public KeyCreateResponse createKey(
@RequestBody KeyCreateRequest keyCreateRequest,
@RequestHeader("Authorization") String authToken) {
return keyService.createKey(keyCreateRequest, authToken);
}
}
The DTOs used in the code for a better understanding of request and response bodies.
public class KeyCreateRequest {
@NonNull
private String apiId;
private String prefix;
private String name;
private Integer byteLength;
private String ownerId;
private Meta meta;
private Integer expires;
private Integer remaining;
private KeyRateLimit ratelimit;
}
public class Meta {
private Map<String, String> meta;
}
public class KeyRateLimit {
private String type;
private Integer limit;
private Integer refillRate;
private Integer refillInterval;
}
public class KeyCreateResponse {
@NonNull
private String key;
@NonNull
private String keyId;
}