Developer forum

Forum » Dynamicweb 10 » Extend Delivery API

Extend Delivery API

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

Is it possible to extend the Delivery API with additional endpoints?
The official documentation seems to miss some information: https://doc.dynamicweb.dev/documentation/extending/extensibilitypoints/services-middleware.html

Thank you,

Adrian


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Adrian,

It depends on what you're trying to achieve.

You can add all the endpoints you want to the solution. As a rule of thumb, you shouldn't use the prefixes /admin or /dwapi for your routes but otherwise you're free to do what you want, be that controllers or middleware, or anything really. It is possible to add new endpoints to the /dwapi route prefix, but it's considered experimental and the APIs may change. If you want to add something to the scope of an existing controller in the Delivery API, that's not possible.

If you can clarify what you want to do, I can better help you further.

- Jeppe

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Jeppe,

Thank you for the response.

My use case is related to an ERP integration. The approach is to change how the communication goes. We have to expose some endpoints for receiving Customer information (Users, Addresses) both with Create and Update and also for receiving Products (Products, Product groups, ProductAttributes, Product Assignment).
At first glance, the current Delivery API supports some if not all of these scenarios.
The flow of data will be minimal as the customer does not have a lot of changes to Customers and Products but I am concerned if something is not supported already by the current Delivery API and we'll have to add new endpoints.
I would try to use a single Authentication and API definition for the entire integration. Hence the question about extending the current Delivery API instead of creating a new one from scratch.

Does it make sense?

Thank you,

Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Adrian

Extending the delivery api  can be 2 things:

  1. Adding new properties to existing response viewmodels - e.g. a new property on a product
  2. Adding new endpoints that receives or send other data than what dwapi does.

My guess is you are looking for option 2.

That would simply mean registering your own endpoints on your own route (url - e.g. /customapi/. That is very simple to do: https://doc.dynamicweb.dev/documentation/extending/middleware/index.html#implementation-example---custom-web-api

If you want to use DW permissions and login using /dwapi authtentication and JWT tokens, you can add the 

[PermissionFilter] (Dynamicweb.Frontend.Classic.Api namespace) attribute to your endpoints.

    [PermissionFilter]
    public IActionResult Some()
    {
        int userId = this.GetUserId();
        User? currentUser = null;
        if (userId > 0)
        {
            currentUser = UserManagementServices.Users.GetUserById(userId);
        }

}

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

I believe both options are useful.
Do you see any potential issues if we use the delivery APi for the purpose described?

Thank you very much.

Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

No - as long as the delivery api exposes the data you need, all is fine.

If you need personalized data (custom prices or permissions) you will need to handle auth and jwt token storage on the consuming sides of things. That is the only thing to be aware of.

 

You must be logged in to post in the forum