Repository navigation
Releases
RDCore.Web v0.1.0-alpha
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'@HttpPostabove a public procedure, compose the project withrdc compose, and runRDCore.Web.Host --RDWeb:Composition <file>. Each request runs the procedure in RD-VBA, on a machine of the program: aFunction's value is the response's JSON body, and a procedure with no value answers204 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
Asthat class, its public members set from the JSON's keys. AnOptionalparameter 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,'@HttpHeadand'@HttpOptions, each with an optional route. APUTand aPATCHtake a JSON body as aPOSTdoes; aDELETEtakes one only for the parameter'@FromBody("name")names; aGET, aHEADand anOPTIONSnever do. Several annotations may serve one function. - An OpenAPI document and a Swagger UI page:
/openapi/v1.jsonis 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./swaggercalls each endpoint from the browser. Both are served in the Development environment, in whichdotnet runstarts the host;--RDWeb:OpenApi trueorfalsedecides it in any environment. - A status code with a message:
RDWeb.Results.Status(404, "No order 7.")answers that status, withOk,Created,NoContent,BadRequest,Forbid,NotFoundandRedirectbeside it. The message of a4xxor a5xxis thedetailof its problem details, as ASP.NET Core'sResults.Problemwrites 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 asRDW00007. A project references theRDWeblibrary 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 parametergame, and the action marked'@NewMachinemakes 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. AnEndstatement disposes the machine, and so does 20 minutes without a request, by default.
Services and startup
Program.Run: a publicSub Runof the standard moduleProgramruns once at startup, given aWebApplicationBuilder. 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,Scopedunless 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,
Createor theFunctionthat'@ControllerFactorynames, and each request's procedure runs on the object the factory returns. - Hooks on a controller: a controller class that implements
RDWeb.IRequestHookanswers a request before its action whenOnRequestreturns a result, and one that implementsRDWeb.IErrorHookanswers its action's run-time error with the resultOnErrorreturns. - 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.
'@Authorizeis 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
'@FromBodynames, 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 composeand 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.