Skip to content

Releases

RDCore.Web v0.1.0-alpha

Pre-release

Choose a tag to compare

@RubberduckAdmin RubberduckAdmin released this 29 Nov 07:19
158e6c9

The first prerelease of RDCore.Web: ASP.NET Core web applications whose controllers are written in RD-VBA, served by an RDCore platform's RDWeb extension.

Warning

This is an alpha prerelease, for evaluation. Expect rough edges, and expect things to change between versions.

RD-VBA in ASP.NET controllers

  • Your RD-VBA module is the controller: write '@Controller("api/orders") in a standard module or a class module and '@HttpGet("{id}") or '@HttpPost above a public procedure, compose the project with rdc compose, and run RDCore.Web.Host --RDWeb:Composition <file>. Each request runs the procedure in RD-VBA, on a machine of the program: a Function's value is the response's JSON body, and a procedure with no value answers 204 No Content. A class module's ACprocedure runs on a new instance, made for its request.
  • Arguments from the request: a parameter named by the route takes the route's value, the others take the query string's, and a JSON body is given to the body parameter: an object of one of your classes when the parameter is declared As that class, its public members set from the JSON's keys. An Optional parameter the request does not give keeps its default.
  • Errors are HTTP errors: a run-time error that the action does not handle answers 500 Internal Server Error, with problem details (application/problem+json) that give the error's number and code.
  • Every REST verb: '@HttpGet, '@HttpPost, '@HttpPut, '@HttpPatch, '@HttpDelete, '@HttpHead and '@HttpOptions, each with an optional route. A PUT and a PATCH take a JSON body as a POST does; a DELETE takes one only for the parameter '@FromBody("name") names; a GET, a HEAD and an OPTIONS never do. Several annotations may serve one function.
  • An OpenAPI document and a Swagger UI page: /openapi/v1.json is an OpenAPI 3.1 document of the endpoints, with the JSON Schemas of each action's parameters, body and value and of the classes they reach. Each operation's summary is its function's '@Description, as a C# action's is its xmldoc summary, and each module's tag is described by its '@ModuleDescription. /swagger calls each endpoint from the browser. Both are served in the Development environment, in which dotnet run starts the host; --RDWeb:OpenApi true or false decides it in any environment.
  • A status code with a message: RDWeb.Results.Status(404, "No order 7.") answers that status, with Ok, Created, NoContent, BadRequest, Forbid, NotFound and Redirect beside it. The message of a 4xx or a 5xx is the detail of its problem details, as ASP.NET Core's Results.Problem writes them, and the message of any other status is the body. A code outside 100 to 599 is run-time error 5, and the editor reports a literal one as RDW00007. A project references the RDWeb library by name, as it references any library: the RDCore.Web extension provides it once it is published into the platform, and the host gives it to the program's machines.

Machines

  • A machine pool: each request runs on a machine of the program, taken from a pool that grows with the load, reset after each request, recycled after a number of requests, and bounded by a deadline per request.
  • Kept machines: '@KeptMachine("game") on a controller keeps a machine for each value of its route parameter game, and the action marked '@NewMachine makes that key's machine. Each other action of the controller runs on its key's machine, one request at a time, with the state the key's earlier requests left. An End statement disposes the machine, and so does 20 minutes without a request, by default.

Services and startup

  • Program.Run: a public Sub Run of the standard module Program runs once at startup, given a WebApplicationBuilder. It registers services (Services.AddScoped, AddTransient, AddSingleton) and filters (UseFilter) that run before each controller, in the order they are added.
  • Services: '@Service("IOrderRepository") in a class module declares a service, Scoped unless it names another lifetime. A parameter of a factory, a filter or a service is given the service its declared type names.
  • Controllers with a default instance: the default instance runs only the factory, Create or the Function that '@ControllerFactory names, and each request's procedure runs on the object the factory returns.
  • Hooks on a controller: a controller class that implements RDWeb.IRequestHook answers a request before its action when OnRequest returns a result, and one that implements RDWeb.IErrorHook answers its action's run-time error with the result OnError returns.
  • Startup errors: a program the host cannot serve, such as a parameter whose type names no service, is refused at startup with a message that says why, and the host serves nothing of it. '@Authorize is a startup error: RDCore.Web signs no user in.

Diagnostics

The RDWeb extension reports the RDW diagnostics in the editor, each with its page:

  • RDW00001: the request body binds to a parameter that no '@FromBody names, with a quick fix that adds it.
  • RDW00002: a parameter of an action that takes a body is bound by neither the route nor the body.
  • RDW00003: an action takes or returns an object of a class whose member does not come back as it went out through JSON.
  • RDW00005: two classes declare one service name with '@Service.
  • RDW00006: a parameter of a factory is not of an object type.
  • RDW00007: a status code outside 100 to 599.

Tested in RD-VBA, end to end

RDCore.Web's own tests serve composed RD-VBA projects through the host over HTTP, so every build runs real RD-VBA controllers: each verb, the JSON body, a run-time error, Status, the OpenAPI document and the Swagger page.

Requirements

  • An RDCore platform: RDCore v0.2.11-alpha, or one built from source, for rdc compose and the RDWeb extension.
  • The .NET 11 SDK: .NET 11.
  • RDCore.SDK 0.2.8-alpha and RDCore.Runtime.Hosting 0.2.11-alpha, from nuget.org.

Installing

This release attaches no files, and RDCore.Web is not published on NuGet: build it from its source at this tag. From the repository root, PublishExtension.ps1 builds the host and publishes it into an RDCore platform as the RDWeb extension:

./PublishExtension.ps1 -PlatformRoot <platform folder>

The documentation has a getting-started guide, in English and French, and the reference.

Full changes: #2 to #20.