release: WRNexusJS 0.8.0
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package wrnexussdk
|
||||
|
||||
import ("bytes"; "encoding/json"; "fmt"; "net/http")
|
||||
type Client struct { BaseURL string; HTTP *http.Client }
|
||||
func (c *Client) Request(method, path string, body any) (map[string]any, error) { data,_:=json.Marshal(body); req,_:=http.NewRequest(method,c.BaseURL+path,bytes.NewReader(data)); req.Header.Set("content-type","application/json"); client:=c.HTTP;if client==nil{client=http.DefaultClient};res,err:=client.Do(req);if err!=nil{return nil,err};defer res.Body.Close();if res.StatusCode>=400{return nil,fmt.Errorf("API status %d",res.StatusCode)};var out map[string]any;err=json.NewDecoder(res.Body).Decode(&out);return out,err }
|
||||
@@ -0,0 +1,3 @@
|
||||
package dev.wrnexus.sdk;
|
||||
import java.net.URI; import java.net.http.*;
|
||||
public final class WrnexusApi { private final String baseUrl; private final HttpClient http = HttpClient.newHttpClient(); public WrnexusApi(String baseUrl){this.baseUrl=baseUrl;} public String request(String method,String path,String json)throws Exception{var request=HttpRequest.newBuilder(URI.create(baseUrl+path)).header("content-type","application/json").method(method,HttpRequest.BodyPublishers.ofString(json==null?"":json)).build();var response=http.send(request,HttpResponse.BodyHandlers.ofString());if(response.statusCode()>=400)throw new IllegalStateException("API status "+response.statusCode());return response.body();} }
|
||||
@@ -0,0 +1,58 @@
|
||||
const request = async (method, path, body, options = {}) => {
|
||||
const response = await globalThis.fetch((options.baseUrl || "") + path, {
|
||||
method,
|
||||
headers: { "content-type": "application/json", ...(options.headers || {}) },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
const value = await response.json();
|
||||
if (!response.ok)
|
||||
throw Object.assign(new Error(value?.error?.message || "API request failed"), {
|
||||
status: response.status,
|
||||
body: value,
|
||||
});
|
||||
return value.data ?? value;
|
||||
};
|
||||
export const postWebhooksPayment = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("POST", `/api/webhooks/payment`, body, options);
|
||||
};
|
||||
export const getUsersCsr = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("GET", `/api/users/csr`, body, options);
|
||||
};
|
||||
export const getUsersSsr = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("GET", `/api/users/ssr`, body, options);
|
||||
};
|
||||
export const postGraphqlExample = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("POST", `/api/graphql-example`, body, options);
|
||||
};
|
||||
export const postTypedUser = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("POST", `/api/typed-user`, body, options);
|
||||
};
|
||||
export const postLogout = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("POST", `/api/logout`, body, options);
|
||||
};
|
||||
export const getHello = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("GET", `/api/hello`, body, options);
|
||||
};
|
||||
export const postLogin = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("POST", `/api/login`, body, options);
|
||||
};
|
||||
export const getEcho = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("GET", `/api/echo`, body, options);
|
||||
};
|
||||
export const postEcho = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("POST", `/api/echo`, body, options);
|
||||
};
|
||||
export const getMe = (params = {}, body, options = {}) => {
|
||||
void params;
|
||||
return request("GET", `/api/me`, body, options);
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import json, urllib.request
|
||||
|
||||
class WrnexusApi:
|
||||
def __init__(self, base_url): self.base_url = base_url.rstrip('/')
|
||||
def request(self, method, path, body=None):
|
||||
data = None if body is None else json.dumps(body).encode()
|
||||
request = urllib.request.Request(self.base_url + path, data=data, method=method, headers={'content-type':'application/json'})
|
||||
with urllib.request.urlopen(request) as response: return json.load(response)
|
||||
def postWebhooksPayment(self, path, body=None): return self.request('POST', path, body)
|
||||
def getUsersCsr(self, path, body=None): return self.request('GET', path, body)
|
||||
def getUsersSsr(self, path, body=None): return self.request('GET', path, body)
|
||||
def postGraphqlExample(self, path, body=None): return self.request('POST', path, body)
|
||||
def postTypedUser(self, path, body=None): return self.request('POST', path, body)
|
||||
def postLogout(self, path, body=None): return self.request('POST', path, body)
|
||||
def getHello(self, path, body=None): return self.request('GET', path, body)
|
||||
def postLogin(self, path, body=None): return self.request('POST', path, body)
|
||||
def getEcho(self, path, body=None): return self.request('GET', path, body)
|
||||
def postEcho(self, path, body=None): return self.request('POST', path, body)
|
||||
def getMe(self, path, body=None): return self.request('GET', path, body)
|
||||
@@ -0,0 +1,109 @@
|
||||
export type RequestOptions = { baseUrl?: string; headers?: HeadersInit };
|
||||
type ApiEnvelope = { data?: unknown; error?: { message?: string } };
|
||||
const request = async (
|
||||
method: string,
|
||||
path: string,
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
const response = await globalThis.fetch((options.baseUrl || "") + path, {
|
||||
method,
|
||||
headers: { "content-type": "application/json", ...(options.headers || {}) },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
const value: ApiEnvelope = await response.json();
|
||||
if (!response.ok)
|
||||
throw Object.assign(new Error(value?.error?.message || "API request failed"), {
|
||||
status: response.status,
|
||||
body: value,
|
||||
});
|
||||
return value.data ?? value;
|
||||
};
|
||||
export const postWebhooksPayment = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("POST", `/api/webhooks/payment`, body, options);
|
||||
};
|
||||
export const getUsersCsr = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("GET", `/api/users/csr`, body, options);
|
||||
};
|
||||
export const getUsersSsr = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("GET", `/api/users/ssr`, body, options);
|
||||
};
|
||||
export const postGraphqlExample = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("POST", `/api/graphql-example`, body, options);
|
||||
};
|
||||
export const postTypedUser = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("POST", `/api/typed-user`, body, options);
|
||||
};
|
||||
export const postLogout = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("POST", `/api/logout`, body, options);
|
||||
};
|
||||
export const getHello = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("GET", `/api/hello`, body, options);
|
||||
};
|
||||
export const postLogin = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("POST", `/api/login`, body, options);
|
||||
};
|
||||
export const getEcho = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("GET", `/api/echo`, body, options);
|
||||
};
|
||||
export const postEcho = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("POST", `/api/echo`, body, options);
|
||||
};
|
||||
export const getMe = (
|
||||
params: Record<string, string> = {},
|
||||
body: unknown,
|
||||
options: RequestOptions = {},
|
||||
) => {
|
||||
void params;
|
||||
return request("GET", `/api/me`, body, options);
|
||||
};
|
||||
Reference in New Issue
Block a user