简体   繁体   中英

OData Action Endpoint not found

I am trying to link my api to braintree payment system. I am using OData but I'm struggling with the routing of my endpoints. I keep getting a 404:

No HTTP resource was found that matches the request URI ' http://localhost:34403/odata/GetPlans '.

Here is where i register my routes in the WebApiConfig class:

var GetPlans = builder.Action("GetPlans");

Should I be using something else besides Action? Maybe return something else?

Here is the endpoint I am trying to hit:

    [HttpGet]
    [ODataRoute("GetPlans")]
    public IHttpActionResult getPlans()
    {
        var gateway = new BraintreeGateway
        {
            Environment = Braintree.Environment.SANDBOX,
            MerchantId = merchId,
            PublicKey = pubKey,
            PrivateKey = privKey
        };

        List<Plan> plans = gateway.Plan.All();

        return Ok(plans);

    }

Actions require the POST http verb, but you have the HttpGet attribute on your method, change it to the POST one and ensure that you are using the POST verb when calling the method. Alternatively, you could change this to be a function, which uses a GET, you would need to use the Function method on the builder instead, like this:

var GetPlans = builder.Function("GetPlans");

A quick summary of the difference between actions and functions from http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/odata-actions-and-functions

Functions are operations that do not have side effects, may support further composition and must have return type.

Actions are operations that allow side effects, such as data modification, and cannot be further composed in order to avoid non-deterministic behavior.

Actions require the POST action because they may have side effects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM