Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Double check the name of the module that contains the Web API controller. </p> <p>Via VS GUI, I created a new web api controller class "TestController.cs" and could not find the correct endpoint url. </p> <p>That is, until I looked at the Module.txt in the project I added the controller to. The project is "Orchard.Users", but the name in the Module.txt file is just "Users".</p> <p>I was able to hit the endpoint at "<a href="http://example.com/api/users/test" rel="nofollow">http://example.com/api/users/test</a>". </p> <p>Noteworthy: I setup a route for this at ".../UsersApi", but the 'auto-magic' URL pattern still works. Code below. Also, I later added a new module to contain my api controller and it would not work until I enabled the module in the dashboard.</p> <p><strong>TestController.cs</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; namespace Orchard.Users.Controllers { public class TestController : ApiController { // GET api/&lt;controller&gt; public IEnumerable&lt;string&gt; Get() { return new string[] { "value1", "value2" }; } // GET api/&lt;controller&gt;/5 public string Get(int id) { return "value"; } // POST api/&lt;controller&gt; public void Post([FromBody]string value) { } // PUT api/&lt;controller&gt;/5 public void Put(int id, [FromBody]string value) { } // DELETE api/&lt;controller&gt;/5 public void Delete(int id) { } } } </code></pre> <p><strong>HttpRoutes.cs</strong></p> <pre><code>using System.Collections.Generic; using Orchard.Mvc.Routes; using Orchard.WebApi.Routes; public class HttpRoutes : IHttpRouteProvider { public void GetRoutes(ICollection&lt;RouteDescriptor&gt; routes) { foreach (RouteDescriptor routeDescriptor in GetRoutes()) { routes.Add(routeDescriptor); } } public IEnumerable&lt;RouteDescriptor&gt; GetRoutes() { return new[] { new HttpRouteDescriptor { Name = "UsersApi", Priority = -10, RouteTemplate = "usersapi/{id}", Defaults = new { area = "Orchard.Users", controller = "Test", id = RouteParameter.Optional }, } }; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload