RSCG–AMS – About My software –WebAPI– part 4

Now it should be an easy way to see in the WebAPI. First, return the data for all software that respected that :

01
02
03
04
05
06
07
08
09
10
public static IEndpointRouteBuilder UseAMS(this IEndpointRouteBuilder endpoints)
{
    endpoints.MapGet("/ams/All", async app =>
    {
                 
            var data = AboutMySoftware.AllDefinitions.Select(it => it).ToArray();
        await app.Response.WriteAsJsonAsync(data);
    });
    return endpoints;
}

Now, how can I make a small html to display things ? I can do with Razor Library – but it is too big and maybe the developers do not want to have this dependency. So I decided for https://www.nuget.org/packages/Transplator/  – fairly easy to use. And is another RSCG that converts template code into C#  code.

So now the code looks like this:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
public static IEndpointRouteBuilder UseAMS(this IEndpointRouteBuilder endpoints)
{
    endpoints.MapGet("/ams/All", async app =>
    {
                 
            var data = AboutMySoftware.AllDefinitions.Select(it => it).ToArray();
        await app.Response.WriteAsJsonAsync(data);
    });
    endpoints.MapGet("/ams/index", app =>
    {
        var response = new ASMTemplate().Render();
        app.Response.ContentType = "text/html";
        return app.Response.WriteAsync(response);
    });
    return endpoints;
}

where the ASMTemplate is

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<style>
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}
 
td {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}
 
th{
background-color: black;
  color: white;
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
  }
tr:nth-child(even) {
  background-color: #dddddd;
}
</style>
 
<table>
<tr>
<th>Nr</td>
<th>Component</th>
<th>Date</th>
<th>Commit</th>
<th>RepoUrl</th>
</tr>
 
{%~ int i=1; ~%}
{%~ foreach(var item in AMS.AboutMySoftware.AllDefinitions){ %}
<tr>
<td>{% i++ %}</td>
<td>{% item.Key %} </td>
<td>{% item.Value.DateGenerated %} </td>
<td>{% item.Value.CommitId %} </td>
<td>{% item.Value.RepoUrl %}</td>
</tr>
{% } %}
</table>

It is time now to make the nuget packages.