-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from felipebaltazar/feature/api-sample
Api sample + Cache Fixes
- Loading branch information
Showing
27 changed files
with
698 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
samples/Maui.ServerDrivenUI.ApiSample/Controllers/ServerDrivenUIController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Reflection; | ||
using System.Text.Json; | ||
|
||
namespace Maui.ServerDrivenUI.ApiSample.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class ServerDrivenUIController : ControllerBase | ||
{ | ||
private readonly ILogger<ServerDrivenUIController> _logger; | ||
|
||
public ServerDrivenUIController(ILogger<ServerDrivenUIController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[HttpGet(Name = "GetUIElement")] | ||
public async Task<ServerUIElement> Get(string key) | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var resourceName = $"{key}.json"; | ||
using var stream = assembly.GetManifestResourceStream(resourceName); | ||
|
||
if (stream is null) | ||
throw new Exception("Resource not found"); | ||
|
||
var result = await JsonSerializer.DeserializeAsync<ServerUIElement>(stream) ?? throw new Exception("Fake api error"); | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Maui.ServerDrivenUI.ApiSample; | ||
|
||
/// <summary> | ||
/// Represents a xaml namespace eg.: xmlns:alias="clr-namespace:namespace;assembly=assembly" | ||
/// </summary> | ||
/// <param name="alias">Define the alias from custom namespaces</param> | ||
/// <param name="namespace">clr-namespace</param> | ||
/// <param name="assembly">Assembly where the custom control is located</param> | ||
public class CustomNamespace(string alias, string @namespace, string? assembly = null) | ||
{ | ||
public string Alias { get; private set; } = alias; | ||
public string Namespace { get; private set; } = @namespace; | ||
public string? Assembly { get; private set; } = assembly; | ||
} |
24 changes: 24 additions & 0 deletions
24
samples/Maui.ServerDrivenUI.ApiSample/Maui.ServerDrivenUI.ApiSample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Remove="Resources\MyView.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="Resources\MyView.json"> | ||
<LogicalName>%(RecursiveDir)%(Filename)%(Extension)</LogicalName> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
6 changes: 6 additions & 0 deletions
6
samples/Maui.ServerDrivenUI.ApiSample/Maui.ServerDrivenUI.ApiSample.http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@Maui.ServerDrivenUI.ApiSample_HostAddress = http://localhost:5102 | ||
|
||
GET {{Maui.ServerDrivenUI.ApiSample_HostAddress}}/weatherforecast/ | ||
Accept: application/json | ||
|
||
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddControllers(); | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
Oops, something went wrong.