Reworked a lot of how REST works
This commit is contained in:
parent
d824e71507
commit
d7012bd094
3 changed files with 58 additions and 22 deletions
52
TShockAPI/RestManager.cs
Normal file
52
TShockAPI/RestManager.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using HttpServer;
|
||||
|
||||
namespace TShockAPI {
|
||||
|
||||
public class RestManager
|
||||
{
|
||||
private Rest Rest;
|
||||
public RestManager(Rest rest)
|
||||
{
|
||||
Rest = rest;
|
||||
}
|
||||
|
||||
public void RegisterRestfulCommands()
|
||||
{
|
||||
Rest.Register(new RestCommand("/HelloWorld/name/{username}", usertest));
|
||||
}
|
||||
|
||||
#region RestMethods
|
||||
//http://127.0.0.1:8080/HelloWorld/name/{username}?type=status
|
||||
object usertest(Dictionary<string, string> verbs, IParameterCollection parameters, RequestEventArgs request)
|
||||
{
|
||||
var ret = new Dictionary<string, string>();
|
||||
var type = parameters["type"];
|
||||
if (type == null)
|
||||
{
|
||||
ret.Add("Error", "Invalid Type");
|
||||
return ret;
|
||||
}
|
||||
if (type == "status")
|
||||
{
|
||||
ret.Add("Users", "Info here");
|
||||
return ret;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Rest.Start();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Rest.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue