Springboot
Create
Create an api key for your users
Pass the optional and required parameters as per the official API docs. See the DTO reference below for more information.
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) {
// Delegate the creation of the key to the KeyService from the SDK
return keyService.createKey(keyCreateRequest, authToken);
}
}
DTOs Reference
The DTOs used in the code for a better understanding of request and response bodies.
Request
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;
}
Response
public class KeyCreateResponse {
@NonNull
private String key;
@NonNull
private String keyId;
}