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 * * 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() { } 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(); } async parseSentence(input: string) { var request: APIRequestParseSentence = { command: "parseSentence", options: { input: input, }, }; var { response } = await this.request(request) as APIResponseParseSentence; return response; } }