Cann't modify a api get endpoint

I am facing a error: i wanted to modify the "person/config" this api endpoints where logic like this,

builder.ModifyQueryBuilder("person/config", method ......)

but after compiling there is a error saying this is not a crud method. can you give me an idea how to modify this API or at least let me know which table it's using underneath.

Parents
  • Hi,

    The person/config method is indeed not a CRUD method, as it does not work with entities. This method builds a .NET result object containing the relevant data.

    You can still modify such a result, but doing so requires a few more steps to get and patch the result object.

    using QBM.CompositionApi.ApiManager;
    using QBM.CompositionApi.Definition;
    using QER.CompositionApi.Portal;
    using System.Net.Http;
    
    namespace QER.CompositionApi
    {
        public class PatchObjectApi : IApiProviderFor<PortalApiProject>
        {
            public void Build(IApiBuilder builder)
            {
                builder.Modify("person/config", m =>
                {
                    var routeVerb = m.RouteProviders.BaseRoute.HttpMethods["GET"];
                    var previous = routeVerb.ResponseBuilderSelector;
    
                    // swap out the response builder
                    routeVerb.ResponseBuilderSelector = new JsonResponseBuilder(async (request, ct) =>
                    {
                        // Call the original response builder to build the result object
                        var message = await previous.Select(request).WriteAsync(request, ct).ConfigureAwait(false);
    
                        // Retrieve the result object
                        var content = (ObjectContent)message.Content;
                        var config = (QER.CompositionApi.Person.UserConfig)content.Value;
    
                        // modify the config object as desired. Example:
                        config.CountPendingRequests = 42;
    
                        return config;
                    });
                });
            }
        }
    }

    Hope this helps,
    Hanno

Reply
  • Hi,

    The person/config method is indeed not a CRUD method, as it does not work with entities. This method builds a .NET result object containing the relevant data.

    You can still modify such a result, but doing so requires a few more steps to get and patch the result object.

    using QBM.CompositionApi.ApiManager;
    using QBM.CompositionApi.Definition;
    using QER.CompositionApi.Portal;
    using System.Net.Http;
    
    namespace QER.CompositionApi
    {
        public class PatchObjectApi : IApiProviderFor<PortalApiProject>
        {
            public void Build(IApiBuilder builder)
            {
                builder.Modify("person/config", m =>
                {
                    var routeVerb = m.RouteProviders.BaseRoute.HttpMethods["GET"];
                    var previous = routeVerb.ResponseBuilderSelector;
    
                    // swap out the response builder
                    routeVerb.ResponseBuilderSelector = new JsonResponseBuilder(async (request, ct) =>
                    {
                        // Call the original response builder to build the result object
                        var message = await previous.Select(request).WriteAsync(request, ct).ConfigureAwait(false);
    
                        // Retrieve the result object
                        var content = (ObjectContent)message.Content;
                        var config = (QER.CompositionApi.Person.UserConfig)content.Value;
    
                        // modify the config object as desired. Example:
                        config.CountPendingRequests = 42;
    
                        return config;
                    });
                });
            }
        }
    }

    Hope this helps,
    Hanno

Children
No Data