Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #47 from tomwarner13/main
Browse files Browse the repository at this point in the history
Support more HTTP verbs
  • Loading branch information
codymullins committed Sep 28, 2023
2 parents 58d6ca0 + b70860a commit 1b580fb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/Spacetime.Core/SpacetimeRestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ public class SpacetimeRestService : ISpacetimeService
private readonly HttpClient _client;
private readonly UrlBuilder _urlBuilder;
private readonly ResponseOptions _defaultResponseOptions = new ();
private readonly Dictionary<string, HttpMethod> _methods = new ()
{
{"GET", HttpMethod.Get },
{"POST", HttpMethod.Post }
};

private readonly IFormatterFactory _formatter;

Expand Down Expand Up @@ -97,7 +92,7 @@ private HttpRequestMessage BuildHttpRequest(SpacetimeRequest request)

// will fail if we add more methods without updating map
// maybe just switch to storing HttpMethod or another enum later
Method = _methods[request.Method],
Method = SupportedHttpMethods.AllMethods[request.Method]
};

if (!string.IsNullOrWhiteSpace(request.RequestBody))
Expand Down
15 changes: 15 additions & 0 deletions src/Spacetime.Core/SupportedHttpMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Spacetime.Core;

public static class SupportedHttpMethods
{
public static readonly Dictionary<string, HttpMethod> AllMethods = new ()
{
{"GET", HttpMethod.Get },
{"POST", HttpMethod.Post },
{"PUT", HttpMethod.Put },
{"PATCH", HttpMethod.Patch },
{"DELETE", HttpMethod.Delete },
{"HEAD", HttpMethod.Head },
{"OPTIONS", HttpMethod.Options }
};
}
6 changes: 4 additions & 2 deletions src/Spacetime/Shared/Components/Rest/RestView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
Icon="@(DrawerOpen ? Icons.Filled.ChevronLeft : Icons.Filled.ChevronRight)"
OnClick="OnDrawerToggle"/>
<MudSelect T="string" Margin="Margin.Dense" T="string" Value="Request.Method" Variant="Variant.Outlined" ValueChanged="OnMethodChange" Class="w-24">
<MudSelectItem Value="@("GET")"/>
<MudSelectItem Value="@("POST")"/>
@foreach (var httpMethodName in SupportedHttpMethods.AllMethods.Keys)
{
<MudSelectItem Value="@httpMethodName"/>
}
</MudSelect>
<MudTextField Class="w-5/6"
Margin="Margin.Dense"
Expand Down

0 comments on commit 1b580fb

Please sign in to comment.