Skip to main content
fixed typos
Source Link
Vinod
  • 2k
  • 3
  • 19
  • 27

You may be looking for something like this

[RoutePrefix("api/items")] public class ItemsController : ApiController { public IHttpActionResult Get() { return Ok(new List<string> { "some results collection" }); } [Route("names")] public IHttpActionResult GetByName([FromUri]string name = null) { if (string.IsNullOrWhiteSpace(name)) { return BadRequest("name is empty"); } return Ok("some result"); } [Route("updates")] public IHttpActionResult GetUpdates([FromUri]string updated = null) { if (string.IsNullOrWhiteSpace(updated)) { return BadRequest("updated is empty"); } return Ok("some result"); } } 

When you invoke these REST endpoints, youyour REST api calls will look something like

GET api/items to retrieve all items

GET api/items/names/john to retrieve by name, if parameter is not supplied, error is returned

GET api/items/updated/test to retrieve updates, if parameter is not supplied, error is returned

You may be looking for something like this

[RoutePrefix("api/items")] public class ItemsController : ApiController { public IHttpActionResult Get() { return Ok(new List<string> { "some results collection" }); } [Route("names")] public IHttpActionResult GetByName([FromUri]string name = null) { if (string.IsNullOrWhiteSpace(name)) { return BadRequest("name is empty"); } return Ok("some result"); } [Route("updates")] public IHttpActionResult GetUpdates([FromUri]string updated = null) { if (string.IsNullOrWhiteSpace(updated)) { return BadRequest("updated is empty"); } return Ok("some result"); } } 

When you invoke these REST endpoints, you calls will look something like

GET api/items to retrieve all items

GET api/items/names/john to retrieve by name, if parameter is not supplied, error is returned

GET api/items/updated/test to retrieve updates, if parameter is not supplied, error is returned

You may be looking for something like this

[RoutePrefix("api/items")] public class ItemsController : ApiController { public IHttpActionResult Get() { return Ok(new List<string> { "some results collection" }); } [Route("names")] public IHttpActionResult GetByName([FromUri]string name = null) { if (string.IsNullOrWhiteSpace(name)) { return BadRequest("name is empty"); } return Ok("some result"); } [Route("updates")] public IHttpActionResult GetUpdates([FromUri]string updated = null) { if (string.IsNullOrWhiteSpace(updated)) { return BadRequest("updated is empty"); } return Ok("some result"); } } 

When you invoke these REST endpoints, your REST api calls will look something like

GET api/items to retrieve all items

GET api/items/names/john to retrieve by name, if parameter is not supplied, error is returned

GET api/items/updated/test to retrieve updates, if parameter is not supplied, error is returned

added 138 characters in body
Source Link
Vinod
  • 2k
  • 3
  • 19
  • 27

You may be looking for something like this

[RoutePrefix("api/items")] public class ItemsController : ApiController {    public IHttpActionResult Get() { return Ok(new List<string> { "some results collection" });  }  [Route("names")] public IHttpActionResult GetByName([FromUri]string name = null) { if (string.IsNullOrWhiteSpace(name)) { return BadRequest("name is empty"); } return Ok("some result"); } [Route("updates")] public IHttpActionResult GetUpdates([FromUri]string updated = null) { if (string.IsNullOrWhiteSpace(updated)) { return BadRequest("updated is empty"); } return Ok("some result"); } } 

When you invoke these REST endpoints, you calls will look something like

GET api/items to retrieve all items

GET api/items/names/john to retrieve by name, if parameter is not supplied, error is returned

GET api/items/updated/test to retrieve updates, if parameter is not supplied, error is returned

You may be looking for something like this

[RoutePrefix("api/items")] public class ItemsController : ApiController { [Route("names")] public IHttpActionResult GetByName([FromUri]string name = null) { if (string.IsNullOrWhiteSpace(name)) { return BadRequest("name is empty"); } return Ok("some result"); } [Route("updates")] public IHttpActionResult GetUpdates([FromUri]string updated = null) { if (string.IsNullOrWhiteSpace(updated)) { return BadRequest("updated is empty"); } return Ok("some result"); } } 

You may be looking for something like this

[RoutePrefix("api/items")] public class ItemsController : ApiController {    public IHttpActionResult Get() { return Ok(new List<string> { "some results collection" });  }  [Route("names")] public IHttpActionResult GetByName([FromUri]string name = null) { if (string.IsNullOrWhiteSpace(name)) { return BadRequest("name is empty"); } return Ok("some result"); } [Route("updates")] public IHttpActionResult GetUpdates([FromUri]string updated = null) { if (string.IsNullOrWhiteSpace(updated)) { return BadRequest("updated is empty"); } return Ok("some result"); } } 

When you invoke these REST endpoints, you calls will look something like

GET api/items to retrieve all items

GET api/items/names/john to retrieve by name, if parameter is not supplied, error is returned

GET api/items/updated/test to retrieve updates, if parameter is not supplied, error is returned

Source Link
Vinod
  • 2k
  • 3
  • 19
  • 27

You may be looking for something like this

[RoutePrefix("api/items")] public class ItemsController : ApiController { [Route("names")] public IHttpActionResult GetByName([FromUri]string name = null) { if (string.IsNullOrWhiteSpace(name)) { return BadRequest("name is empty"); } return Ok("some result"); } [Route("updates")] public IHttpActionResult GetUpdates([FromUri]string updated = null) { if (string.IsNullOrWhiteSpace(updated)) { return BadRequest("updated is empty"); } return Ok("some result"); } }