Implementation
You can always refer to the Sample application for a working example of how to use the package.
How to implement OCPI modules using OCPI.Net
Apply OcpiEndpoint
attribute to your module controllers to specify their OCPI versions. The package will perform an automated scan of your controllers and generate a list of supported OCPI versions for each module.
[OcpiEndpoint(OcpiModule.Credentials, "Receiver", "2.2.1")]
[Route("2.2.1/credentials")]
public class OcpiCredentialsController : OcpiController
{
// Implement your module methods here
}
⚠️ The OCPI.Net Versioning implementation requires your OCPI endpoint routes to contain the ocpi version this route is used for.
For example, if your OCPI version is
2.2.1
, the controller implementing this OCPI Module should have at least 1 route with2.2.1
in it. This allows the package to determine which routes are intended for which OCPI version.
Refer to the Versioning section for more information on OCPI module versioning.
Use the OcpiOk
method of the OcpiController
class to generate OCPI-compliant responses:
[HttpGet]
public IActionResult Get()
{
var result = new OcpiCredentials()
{
Token = "Requesting-Platform's-Credentials-Token",
Url = "Your-Service's-Versions-Endpoint-Url"
};
return OcpiOk(result);
}
Use OcpiOk
with a PageResult<T>
to generate an OCPI-compliant paginated response. See more: Pagination
Customizing the package to meet specific business needs
The package is designed to be as flexible as possible, allowing you to implement OCPI modules in any way you see fit. The package contains a number of services which are used to perform various tasks such as validating incoming requests, generating responses, and handling errors.
You are not forced to use any of these services, and you can implement your own services if you wish. The package also allows you to override some of the default services with your own custom implementations.
Refer to the Architecture section for more information on the package's internal architecture.