yum-slop/TaSTT

Free self-hosted STT for VRChat.

git clone https://git.yummers.dev/yum-slop/TaSTT

yumBegin work on custom webserverfa59ca6

master
1.6 KiB76 linesraw

This is the API design of the webserver supporting the browser source.

I tried oatpp but it had a nasty habit of randomly crashing. I looked at crowCPP but it depends on boost, which I have a personal grudge against. So I'm making Yet Another Web Framework.

This one supports only the minimum feature set required to implement the browser source.

The browser source requires two APIs:

  1. GET /: return index.html (html)
  2. GET /api/transcript: return transcript (json)
enum ContentType {
  HTTP,
  JSON,
};

class WebServer:
public:
  WebServer(u16 port)

  // method and path are in-params
  // payload and type are out-params
  typedef handler_t std::function<void(const string method, const string path,
      string& payload, ContentType& type);

  void RegisterPathHandler(string method, string path, handler_t handler);

  Run(volatile bool* run)

We need a way to generate HTML from responses:

class HTTPMapper:
  HTTPMapper()

  void Map(const string method, const string path, const string payload, const
      ContentType type) = 0;

class HTTPMapperHTML : public HTTPMapper:
  HTTPMapperHTML()

  ...

class HTTPMapperJSON : public HTTPMapper:
  HTTPMapperJSON()

  ...

We also need a way to parse client-sent HTML:

class HTTPParser:
  HTTPParser()

  bool Parse(const string payload)

  string GetMethod();
  string GetPath();
  bool GetHeader(const string header, string value)

  bool GetPayload()

WebServer hides HTTPMapper. WebServer and HTTPMapper share ContentType.

So we have

WebCommon.h: shared types HTTPParser.h: supporting API for WebServer HTTPMapper.h: supporting API for WebServer WebServer.h: user-visible API

1This is the API design of the webserver supporting the browser source.
2
3I tried oatpp but it had a nasty habit of randomly crashing. I looked at
4crowCPP but it depends on boost, which I have a personal grudge against.
5So I'm making Yet Another Web Framework.
6
7This one supports only the minimum feature set required to implement the
8browser source.
9
10The browser source requires two APIs:
111. GET /: return index.html (html)
122. GET /api/transcript: return transcript (json)
13
14```
15enum ContentType {
16  HTTP,
17  JSON,
18};
19
20class WebServer:
21public:
22  WebServer(u16 port)
23
24  // method and path are in-params
25  // payload and type are out-params
26  typedef handler_t std::function<void(const string method, const string path,
27      string& payload, ContentType& type);
28
29  void RegisterPathHandler(string method, string path, handler_t handler);
30
31  Run(volatile bool* run)
32```
33
34We need a way to generate HTML from responses:
35```
36class HTTPMapper:
37  HTTPMapper()
38
39  void Map(const string method, const string path, const string payload, const
40      ContentType type) = 0;
41
42class HTTPMapperHTML : public HTTPMapper:
43  HTTPMapperHTML()
44
45  ...
46
47class HTTPMapperJSON : public HTTPMapper:
48  HTTPMapperJSON()
49
50  ...
51```
52
53We also need a way to parse client-sent HTML:
54```
55class HTTPParser:
56  HTTPParser()
57
58  bool Parse(const string payload)
59
60  string GetMethod();
61  string GetPath();
62  bool GetHeader(const string header, string value)
63
64  bool GetPayload()
65```
66
67WebServer hides HTTPMapper.
68WebServer and HTTPMapper share ContentType.
69
70So we have
71
72  WebCommon.h: shared types
73  HTTPParser.h: supporting API for WebServer
74  HTTPMapper.h: supporting API for WebServer
75  WebServer.h: user-visible API
76