---
title: "How do I use WebAPI/Rest correctly when other params are needed"  
description: "How do I use WebAPI/Rest correctly when other params are needed"  
author: "Anonymous User"  
published: 2014-12-05  
updated: 2014-12-05  
canonical: https://www.mindstick.com/forum/12745/how-do-i-use-webapi-rest-correctly-when-other-params-are-needed  
category: "asp.net"  
tags: ["api(s)", "web"]  
reading_time: 2 minutes  

---

# How do I use WebAPI/Rest correctly when other params are needed

I am new to WebAPI and rest and [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to do things correctly. By default if I were to access something such as User I would call api/user/5 if I wanted user 5. This would go to my User [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) to Get(int num) I think. But I know I will often need other params passed as well. Currently I have Get(JObject data), but that data param is for other parameters. I will need other [optional](https://www.mindstick.com/interview/22851/main-difference-between-optional-and-required-keywords) params whether I am sending an ID or wanting a list of everything. How do I go about [organizing](https://www.mindstick.com/articles/310791/all-you-need-to-know-about-organizing-before-moving) [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) properly with WebAPI? Am I misunderstanding something?

To clarify: This [question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time) is more about REST than dynamic objects, though they play a part:

How do I get a single [resource](https://www.mindstick.com/blog/43433/top-best-resources-for-women-about-beauty-and-health) vs a list of [resources](https://yourviews.mindstick.com/view/293/renovation-causes-wastage-of-resources) when I need additional params. I see those [concepts](https://www.mindstick.com/articles/13127/macro-and-microeconomics-concepts-in-relation-to-global-organization-management) as [two separate](https://www.mindstick.com/forum/159375/how-to-communicate-with-two-separate-database-in-mssql-server) methods, but the additional params complicate it in my mind when routing is involved.

## Replies

### Reply by Lillian Martin

I think you should make a new object for each WebAPI function that will handle the request. You can make the parameters optional with nullable properties.

```
[HttpPost]public void SampleFunction(SampleFunctionModel model){ }
```

where SampleFunctionModel is:\
\

```
public class SampleFunctionModel{    public int? Id {get; set; }     public string Name{ get; set; }}
```

### Reply by Elena Glibart

Use attribute routing

## For example -

```
[Route("customers/{customerId}/orders")]public IEnumerable<Order> GetOrdersByCustomer(int
customerId) { ... }or [Route("customers/{customerId}/orders/{orderId}")]public Order GetOrderByCustomer(int customerId, int orderId)
{ ... }
```

if you need to return a list, create a method that returns a list, otherwise return the specific item requested


---

Original Source: https://www.mindstick.com/forum/12745/how-do-i-use-webapi-rest-correctly-when-other-params-are-needed

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
