aboutsummaryrefslogtreecommitdiff
path: root/core/http/client.ts
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-06-29 14:25:29 +0200
committerlonkaars <loek@pipeframe.xyz>2023-06-29 14:25:29 +0200
commit3f7ae147fb969db479c10eaa871a840a30e281b3 (patch)
tree2e99c35f59f0effb260c26118e9edf3199bb8de7 /core/http/client.ts
parentc998e1c0477d51c886f9e4246e102dec4d7ef8dd (diff)
http proof of concept api
Diffstat (limited to 'core/http/client.ts')
-rw-r--r--core/http/client.ts33
1 files changed, 24 insertions, 9 deletions
diff --git a/core/http/client.ts b/core/http/client.ts
index 42d75f0..a77b616 100644
--- a/core/http/client.ts
+++ b/core/http/client.ts
@@ -1,7 +1,9 @@
-import { ParseDepth, ParseResult } from "../../language/types.ts";
-import YomikunError from "../../util/error.ts";
+import "../../util/array.ts";
+
+import { ParseResult } from "../../language/types.ts";
import API from "../api.ts";
import { ConnectionProps, ConnectionPropsDefault } from "./props.ts";
+import { APIRequest, APIRequestParseSentence, APIResponseParseSentence } from "./types.ts";
/**
* @summary Yomikun HTTP API
@@ -18,14 +20,27 @@ export default class YomikunRemoteAPIClient implements API {
async prepare() { }
- async parseSentence(input: string) {
- var response = await fetch(`http://${this.props.host}:${this.props.port}/parseSentence`);
- console.log(response.body);
+ private async request(details: APIRequest) {
+ var response = await fetch(`http://${this.props.host}:${this.props.port}`, {
+ method: "POST",
+ headers: {
+ "Accept": "application/json",
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(details),
+ });
+ return response.json();
+ }
- return {
- depth: ParseDepth.Term,
- tokens: [],
- } as ParseResult;
+ async parseSentence(input: string) {
+ var request: APIRequestParseSentence = {
+ command: "parseSentence",
+ options: {
+ input: input,
+ },
+ };
+ var { response } = await this.request(request) as APIResponseParseSentence;
+ return response;
}
}