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