Bumped package version to 1.4.7. Added support for Stream requests and MemoryStream responses.

This commit is contained in:
2023-03-31 08:21:32 -07:00
parent fe99ba9b9d
commit cf477522c0
5 changed files with 221 additions and 65 deletions

View File

@ -75,7 +75,9 @@ namespace MontoyaTech.Rest.Net.Example
new Route<string>(HttpRequestMethod.Get, "/auth/{username}", Exists),
new Route(HttpRequestMethod.Post, "/auth/signup", Signup),
new Route(HttpRequestMethod.Get, "/auth/", Json),
new Route(HttpRequestMethod.Get, "/auth/role", GetRole)
new Route(HttpRequestMethod.Get, "/auth/role", GetRole),
new Route(HttpRequestMethod.Post, "/upload", Upload),
new Route(HttpRequestMethod.Get, "/download", Download)
);
string code = listener.GenerateCSharpClient();
@ -110,6 +112,24 @@ namespace MontoyaTech.Rest.Net.Example
Console.WriteLine($"Rest api server running at {listener.BaseUrl}");
StaticClient.Init(listener.BaseUrl);
using (var stream = new MemoryStream())
{
var bytes = Encoding.UTF8.GetBytes("hello world!");
stream.Write(bytes, 0, bytes.Length);
StaticClient.Stream.Upload(stream);
}
using (var stream = StaticClient.Stream.Download())
{
var str = Encoding.UTF8.GetString(stream.ToArray());
Console.WriteLine("Download output:" + str);
}
listener.Block();
}
@ -182,5 +202,23 @@ namespace MontoyaTech.Rest.Net.Example
{
return context.Response.WithStatus(HttpStatusCode.OK).WithJson(new User("Rest.Net"));
}
[RouteGroup("Stream")]
[RouteRequest(typeof(MemoryStream))]
public static HttpListenerResponse Upload(HttpListenerContext context)
{
var content = context.Request.ReadAsString();
Console.WriteLine("Uploaded:" + content);
return context.Response.WithStatus(HttpStatusCode.OK);
}
[RouteGroup("Stream")]
[RouteResponse(typeof(MemoryStream))]
public static HttpListenerResponse Download(HttpListenerContext context)
{
return context.Response.WithStatus(HttpStatusCode.OK).WithText("Hello world");
}
}
}