aboutsummaryrefslogtreecommitdiff
path: root/core/http
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-06-28 23:59:50 +0200
committerlonkaars <loek@pipeframe.xyz>2023-06-28 23:59:50 +0200
commit67dbb6421976254658c5e38045513129dd18187a (patch)
tree288b599d1097b26bdbcad3b6749b38e133017cf2 /core/http
initial public commit
Diffstat (limited to 'core/http')
-rw-r--r--core/http/client.ts31
-rw-r--r--core/http/props.ts10
-rw-r--r--core/http/server.ts33
3 files changed, 74 insertions, 0 deletions
diff --git a/core/http/client.ts b/core/http/client.ts
new file mode 100644
index 0000000..42d75f0
--- /dev/null
+++ b/core/http/client.ts
@@ -0,0 +1,31 @@
+import { ParseDepth, ParseResult } from "../../language/types.ts";
+import YomikunError from "../../util/error.ts";
+import API from "../api.ts";
+import { ConnectionProps, ConnectionPropsDefault } from "./props.ts";
+
+/**
+ * @summary Yomikun HTTP API
+ *
+ * Uses the Yomikun server to call API methods. Handles (de)serialization
+ * automatically.
+ */
+export default class YomikunRemoteAPIClient implements API {
+ private props: ConnectionProps;
+
+ constructor(options?: ConnectionProps) {
+ this.props = { ...ConnectionPropsDefault, ...options };
+ }
+
+ async prepare() { }
+
+ async parseSentence(input: string) {
+ var response = await fetch(`http://${this.props.host}:${this.props.port}/parseSentence`);
+ console.log(response.body);
+
+ return {
+ depth: ParseDepth.Term,
+ tokens: [],
+ } as ParseResult;
+ }
+}
+
diff --git a/core/http/props.ts b/core/http/props.ts
new file mode 100644
index 0000000..d69ae55
--- /dev/null
+++ b/core/http/props.ts
@@ -0,0 +1,10 @@
+export interface ConnectionProps {
+ host: string;
+ port: number;
+};
+
+export const ConnectionPropsDefault: ConnectionProps = {
+ host: "localhost",
+ port: 9400,
+};
+
diff --git a/core/http/server.ts b/core/http/server.ts
new file mode 100644
index 0000000..8a6786e
--- /dev/null
+++ b/core/http/server.ts
@@ -0,0 +1,33 @@
+import { serve } from "https://deno.land/std@0.192.0/http/server.ts";
+
+import { ParseResult } from "../../language/types.ts";
+import YomikunRAWAPI from "../raw/api.ts";
+import { ConnectionProps, ConnectionPropsDefault } from "./props.ts";
+
+interface Endpoint {
+ endpoint: string;
+};
+
+export default class YomikunRemoteAPIServer extends YomikunRAWAPI {
+ private props: ConnectionProps;
+
+ constructor(options?: ConnectionProps) {
+ super();
+ this.props = { ...ConnectionPropsDefault, ...options };
+ }
+
+ async parseSentence(input: string) {
+ return await super.parseSentence(input);
+ }
+
+ async start() {
+ serve((req) => {
+ return new Response("Hello world!");
+ }, { port: this.props.port });
+ }
+
+ async prepare() {
+ await super.prepare();
+ }
+}
+