- Plugin basics
- Introduction
- Platform overview
- Plugin guides
- First UI package
- Package registration
- First Backend package
- Portal package creation
- REST API
- REST API using
-
Request Formats
- HTTP GET: Getting a list of elements of type Entity
- HTTP GET: Getting a specific Element of the Entity Type
- HTTP PUT: Editing an Entity Type Element
- HTTP POST: Creating a new Element of Entity Types
- HTTP POST: Doing an Action for Element of Entity Types
- HTTP POST: Creating an new element Sub-Entity of Types
- HTTP DELETE: Deleting the element of Entity Types
- HTTP PATCH: Partially editing the element of Entity Types
- Handling Errors When Calling HTTP Methods
Creation of Backend package from template
You have got to install an IDE with support for writing code in the C# programming language. VisualStudio was used to write this guide.
Also is required the Dotnet CLI
Repository cloning
Let's start the development with the GIT repository cloning tutorial-backend-plugin.
git clone https://github.com/mef-dev/tutorial-backend-plugin/tree/ibackend-plugin
Content overview
After cloning and opening the solution, the content will be like that:
The unique identifier whithin the platform is the assembly name as well as the entity name within the particular alias. When creating your own project, rename the project to change assemply name and modify the name of the entity as you want.
Implementation
The MEF.DEV platform supports the REST architectural style of development in order to use HTTP methods for operations instead of writing different service names for each operation. Below is a list of methods used in the platform and their properties are mapped to each entity:
GET
: This method is safe and idempotent. It is usually used for information and has no side effectsPOST
: This method is not secure, but it is idempotent in the REST API implementation - this is done to backward compatibility in legacy systems that do not support the PUT method. This method is most often used to create entitiesPUT
: This method is idempotent, so it is better to use this method instead of POST to update resources. Avoid using POST to update resources, except for entities that require historical changes to be changed, such as addresses or profiles
Let's consider the methods in more detail:
BaseEntity Post
(string lang, BaseEntity entity, string parent = null);BaseEntity Put
(string id, string lang, BaseEntity entity);
These methods accept the BaseEntity
inherited class data model. In order for the MEF.DEV platform to know which specific class should be used to deserialize the request, the same attribute used to mark the entity as exported (for example entityName
in the screenshot above) is used, namely ExportAttribute
.
The key point is that the values of this attribute have got to match!
For example, if there is an exported class
[Export("accounts", typeof(IBackendPlugin)])
public sealed class AccountsEntity : IBackendPlugin
{
}
then it is have got to describe the model for the methods POST
і PUT
[Export("accounts", typeof(BaseEntity))]
public sealed class AccountsRequest : BaseEntity
{
}
Build
To build the package you can use the command below:
dotnet publish -o bin\Deploy --force
After successful build operation, you have got to archive the content of bin\Deploy
folder into ZIP file.
Registration package
Let's start registration process with the package creation page, it should be done the only once
Note. This functionality is available to users with Developer Admin and Developer roles within mef.dev technical preview
The package creation page you can find under the Plugins
menu. After clicking the Add button, we get to the plugin creation page. In this case, we need to specify the details of the new plugin below:
- ALIAS - the name of the subject area of the package, which is used to combine packages by functional purpose (logical group). Should be noted that package names cannot intersect within one ALIAS name.
- NAME - the package name.
After entering this data, we will pass to a choice of package type. At this time the platform supports 4 main package types - the purpose of each type and the differences between them are written in the help (green block). Now we are interested in the Service
type - a package oriented to handle the requests from UI components without specific tenant configuration, so we choose it.
After the selection, our Backend
block was activated to user input. It contains only one field PluginMefName
. This is the project assembly name. Enter the name and click Save.
When all fields are filed correctly, you will be directed to the package configuration page.
Note. Futher, you can navigate to it via the
Configure
sub-menu in the selected row menu, located in the last column of table on the page Plugins
Uploading version of package
The updated or initial package version is uploaded from the Backend block. When you click on the Upload button, you have got to select the ZIP archive with collected package content from the folder witn name: bin\Deploy
.
It is not allowed to upload has already uploaded version - so it is important to manage the package versioning and do changes of the assembly version in the project properties. After uploading, you have got to switch to the uploaded version and click Save
Package Dry run
You can make dry run of the package with any API tools. In this guide, the Postman will be used.
You should be authorized to send HTTP requests - usually, the authorization scheme with the user token is used, but we will use Basic Auth
for dry runs. You can create the required login-password pair under the SETTINGS\CREDENTIALS section of your profile on the platform, accessed by clicking on the user icon in the upper right corner. After clicking on the ADD
button you will be able to set up the user login and password with the Basic Auth authorization type.
Basic health check
From a technical perspective, the platform provides you the endpoint for the package's version check within the platform:
https://preview.mef.dev/api/v1/<alias>/plugins/<PluginMefName>/version.json?detaillevel=detailed
In case of a similar result, your package was uploaded on the platform successfully.
Standard Package requests
Sending the standard requests to the package will be demonstrated by the GET requests examples.
To send requests you have got to use the URL path below:
https://preview.mef.dev/api/v1/<alias>/<EntityName>
Design-wise, you can develop and add any parameters, headers, and fields within the request, but you should handle them with the input and output models of the package. To operate with the platform with specific tasks, you should use ServiceProvider from the context
Specific Action requests
To implement specific logic which should outstanding of standard HTTP methods, you have got to use the Action implementation over the POST method. An example you can find with the URL path below:
https://preview.mef.dev/api/v1/<alias>/<EntityName>/<ActionName>.json
The implementation of these requests also is available by the Angular application package example tutorial-ui-plugin