1 module rest.iapiv1;
2 
3 import vibe.d;
4 
5 /++
6 	Interface definition for JSON REST  API.
7 +/
8 interface IApiV1
9 {
10 	/+
11 		POST /api/v1/run
12 		{
13 			source: "...",
14 			compiler: "dmd" (available: ["dmd-nightly", "dmd-beta", "dmd", "ldc-beta", "ldc", "gdc"])
15 		}
16 
17 		Returns: output of compiled D program with success
18 		flag and parsed errors and warnings (if any
19 		and success is false).
20 		{
21 			output: "Program Output",
22 			success: true/false
23 		}
24 	+/
25 	struct RunOutput
26 	{
27 		string output;
28 		bool success;
29 		struct Message {
30 			int line;
31 			string message;
32 		}
33 		Message[] errors;
34 		Message[] warnings;
35 	}
36 
37 	struct RunInput
38 	{
39 		string source;
40 		@optional string compiler = "dmd";
41 		@optional string stdin;
42 		@optional string args;
43 		@optional bool color;
44 	}
45 
46 	@bodyParam("input")
47 	@method(HTTPMethod.POST)
48 	@path("/api/v1/run")
49 	RunOutput run(RunInput input);
50 
51 	/+
52 		POST /api/v1/format
53 		{
54 			source: "..."
55 		}
56 
57 		Returns: formatted source code of given D source
58 		with success flag
59 		{
60 			source: "void main() {}",
61 			success: true/false
62 		}
63 	+/
64 	struct FormatOutput
65 	{
66 		string source;
67 		bool success;
68 	}
69 	@method(HTTPMethod.POST)
70 	@path("/api/v1/format")
71 	FormatOutput format(string source);
72 
73 	/+
74 		POST /api/v1/shorten
75 		{
76 			source: "...",
77 			compiler: "dmd" (available: ["dmd-nightly", "dmd-beta", "dmd", "ldc-beta", "ldc", "gdc"]),
78 			args: ""
79 		}
80 
81 		Returns: short url to given D source
82 		with success flag
83 		{
84 			source: "https://is.gd/abc",
85 			success: true/false
86 		}
87 	+/
88 	struct ShortenOutput
89 	{
90 		string url;
91 		bool success;
92 	}
93 	@method(HTTPMethod.POST)
94 	@path("/api/v1/shorten")
95 	ShortenOutput shorten(string source, string compiler, string args);
96 
97 	/+
98 		POST /api/v1/gi
99 		{
100 			source: "...",
101 			compiler: "dmd" (available: ["dmd-nightly", "dmd-beta", "dmd", "ldc-beta", "ldc", "gdc"]),
102 			args: ""
103 		}
104 
105 		Returns: short url to given D source
106 		with success flag
107 		{
108 			id: "abcdef",
109 			url: "/gist/abcdef",
110 			htmlUrl: "http://gist.github.com/abcdef",
111 		}
112 	+/
113 
114 	struct GistOutput
115 	{
116 		string id;
117 		string url;
118 		string htmlUrl;
119 	}
120 	@method(HTTPMethod.POST)
121 	@path("/api/v1/gist")
122 	GistOutput gist(string source, string compiler, string args);
123 
124 	/+
125 		GET /api/v1/source/CHAPTER/SECTION
126 
127 		Returns: source code (or empty if none) for the given
128 		chapter and section. Also returns changed source code
129 		if user switched between sections.
130 		{
131 			sourceCode: "..."
132 		}
133 	+/
134 	struct SourceOutput
135 	{
136 		string sourceCode;
137 	}
138 	@method(HTTPMethod.GET)
139 	@path("/api/v1/source/:language/:chapter/:section")
140 	SourceOutput getSource(string _language, string _chapter, string _section);
141 }