Added example for how all additional endpoints should respond in regards to success and failure.

Added example endpoint that demonstrates rest verbs.
This commit is contained in:
Lucas Nicodemus 2011-09-04 23:59:44 -06:00
parent 332fe805a9
commit 319f369799
2 changed files with 14 additions and 2 deletions

View file

@ -36,5 +36,5 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.3.0.0905")]
[assembly: AssemblyFileVersion("3.3.0.0905")]
[assembly: AssemblyVersion("3.3.0.0904")]
[assembly: AssemblyFileVersion("3.3.0.0904")]

View file

@ -17,9 +17,21 @@ namespace TShockAPI {
public void RegisterRestfulCommands()
{
Rest.Register(new RestCommand("/HelloWorld/name/{username}", usertest));
//Rest.Register(new RestCommand("/wizard/{username}", wizard));
}
#region RestMethods
//The Wizard example, for demonstrating the response convention:
object wizard(RestVerbs verbs, IParameterCollection parameters, RequestEventArgs request)
{
var returnBack = new Dictionary<string, string>();
returnBack.Add("status", "200"); //Keep this in everything, 200 = ok, etc. Standard http status codes.
returnBack.Add("error", "(If this failed, you would have a different status code and provide the error object.)"); //And only include this if the status isn't 200 or a failure
returnBack.Add("Verified Wizard", "You're a wizard, " + verbs["username"]); //Outline any api calls and possible responses in some form of documentation somewhere
return returnBack;
}
//http://127.0.0.1:8080/HelloWorld/name/{username}?type=status
object usertest(RestVerbs verbs, IParameterCollection parameters, RequestEventArgs request)
{