From 67dbb6421976254658c5e38045513129dd18187a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 28 Jun 2023 23:59:50 +0200 Subject: initial public commit --- core/http/client.ts | 31 +++++++++++++++++++++++++++++++ core/http/props.ts | 10 ++++++++++ core/http/server.ts | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 core/http/client.ts create mode 100644 core/http/props.ts create mode 100644 core/http/server.ts (limited to 'core/http') 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(); + } +} + -- cgit v1.2.3