Skip to content

Commit

Permalink
Allow empty uri in RestRequest.
Browse files Browse the repository at this point in the history
  • Loading branch information
o.nadymov committed Jun 26, 2024
1 parent c327ace commit 55b1787
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/Spoleto.RestClient/RestRequest/RestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ public record RestRequest : IRestRequest

private readonly Dictionary<string, string> _headers = [];

public RestRequest(RestHttpMethod httpMethod)
: this(httpMethod, string.Empty, null)
{
}

public RestRequest(RestHttpMethod httpMethod, string uri)
: this(httpMethod, uri, null)
{
}

public RestRequest(RestHttpMethod httpMethod, string uri, HttpContent? content = null)
{
if (uri == null)
throw new ArgumentNullException(nameof(uri));

Method = httpMethod;
Uri = uri;
_content = content;
Expand Down
16 changes: 11 additions & 5 deletions src/Spoleto.RestClient/RestRequest/RestRequestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ public class RestRequestFactory
private HttpContent? _content;
private readonly Dictionary<string, string> _headers = [];

/// <summary>
/// Constructor with parameter.
/// </summary>
public RestRequestFactory(RestHttpMethod method)
: this(method, string.Empty)
{
}

/// <summary>
/// Constructor with parameters.
/// </summary>
public RestRequestFactory(RestHttpMethod method, string requestUri)
{
if (requestUri == null)
throw new ArgumentNullException(nameof(requestUri), "Request URI is required");

_method = method;
_requestUri = requestUri;
}
Expand Down Expand Up @@ -180,11 +191,6 @@ public RestRequestFactory WithBearerToken(string token)

public RestRequest Build()
{
if (string.IsNullOrEmpty(_requestUri))
{
throw new InvalidOperationException("Request URI is required");
}

var uri = _requestUri;
if (!string.IsNullOrEmpty(_query))
{
Expand Down

0 comments on commit 55b1787

Please sign in to comment.