Click here to Skip to main content
15,889,992 members
Home / Discussions / Web Development
   

Web Development

 
PinnedHow to get an answer to your question Pin
Chris Maunder4-Sep-10 2:25
cofounderChris Maunder4-Sep-10 2:25 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder12-Jul-09 22:40
cofounderChris Maunder12-Jul-09 22:40 
QuestionSwagger Generated URL Questtion Pin
Kevin Marois26-Apr-24 12:37
professionalKevin Marois26-Apr-24 12:37 
AnswerRe: Swagger Generated URL Questtion Pin
Dave Kreskowiak26-Apr-24 12:55
mveDave Kreskowiak26-Apr-24 12:55 
GeneralRe: Swagger Generated URL Questtion Pin
Kevin Marois26-Apr-24 13:37
professionalKevin Marois26-Apr-24 13:37 
GeneralRe: Swagger Generated URL Questtion Pin
Dave Kreskowiak26-Apr-24 14:13
mveDave Kreskowiak26-Apr-24 14:13 
GeneralRe: Swagger Generated URL Questtion Pin
Kevin Marois26-Apr-24 14:17
professionalKevin Marois26-Apr-24 14:17 
QuestionASP.Net MVC Core API Question Revisited Pin
Kevin Marois18-Apr-24 19:44
professionalKevin Marois18-Apr-24 19:44 
I posted on this yesterday, but I haven't made any progress.

I'm just trying to set up a simplet test API. Here's my controller:
[Route("api/user")]
[ApiController]
public class UserController : _ControllerBase
{
    public UserController(IConfiguration configuration) :
        base(configuration)
    {
    }

    [HttpGet("getById/{id}")]
    public IActionResult GetById([FromQuery]int id)
    {
        try
        {
            var repo = new Repository(GetDataContext());

            var owner = repo.GetById(id);

            if (owner is null)
            {
                return NotFound();
            }
            else
            {
                return Ok(owner);
            }
        }
        catch (Exception ex)
        {
            return StatusCode(500, "Internal server error");
        }
    }

    [HttpGet]
    public IActionResult GetAll()
    {
        try
        {
            var repo = new Repository(GetDataContext());

            var owners = repo.GetAll();

            return Ok(owners);
        }
        catch (Exception ex)
        {
            return StatusCode(500, "Internal server error");
        }
    }

    [HttpPost]
    public IActionResult Test([FromBody]TestEntity testEntity)
    {
        return StatusCode(200);
    }
}
I can call the first two methods, GetAll and GetById like this:
https: //localhost:5001/api/User
and
https: //localhost:5001/api/User/GetById/1
and they both return data. But this gives me a Not Found error
[HttpPost]
public IActionResult Test([FromBody]TestEntity testEntity)
{
//...
}
called using Postman like this:
https: //localhost:5001/api/User/test/{"id": 10,"name": Someone Else}

Questions
First, I'm not even sure I have the controller methods set up right. I don't really understand when/why to use the various attributes such as [FromBody] & [FromQuery]. I'm slowly learning by I may have it wrong here.

If I'm passing an object, as opposed to say an int, what should the method signature look like? Do I use FromBody or FromQuery? My Google searches return many different results. What would the correct syntax look like?

Second, the way I'm passing params, seperated by '/' seems wrong. Shouldn't the call to the API look something like this?
https: //localhost:2001/api/User/GetById?id=123
Am I doing something wrong here?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.

AnswerRe: ASP.Net MVC Core API Question Revisited Pin
Richard Deeming18-Apr-24 21:27
mveRichard Deeming18-Apr-24 21:27 
GeneralRe: ASP.Net MVC Core API Question Revisited Pin
Kevin Marois19-Apr-24 4:20
professionalKevin Marois19-Apr-24 4:20 
GeneralRe: ASP.Net MVC Core API Question Revisited Pin
Richard Deeming19-Apr-24 4:43
mveRichard Deeming19-Apr-24 4:43 
GeneralRe: ASP.Net MVC Core API Question Revisited Pin
Kevin Marois19-Apr-24 5:19
professionalKevin Marois19-Apr-24 5:19 
GeneralRe: ASP.Net MVC Core API Question Revisited Pin
Kevin Marois21-Apr-24 12:22
professionalKevin Marois21-Apr-24 12:22 
GeneralRe: ASP.Net MVC Core API Question Revisited Pin
Richard Deeming29-Apr-24 23:53
mveRichard Deeming29-Apr-24 23:53 
QuestionASP.Net MVC Core API Question Pin
Kevin Marois17-Apr-24 20:06
professionalKevin Marois17-Apr-24 20:06 
AnswerRe: ASP.Net MVC Core API Question Pin
Pete O'Hanlon17-Apr-24 20:34
mvePete O'Hanlon17-Apr-24 20:34 
GeneralRe: ASP.Net MVC Core API Question Pin
Kevin Marois18-Apr-24 11:54
professionalKevin Marois18-Apr-24 11:54 
SuggestionRe: ASP.Net MVC Core API Question Pin
Richard Deeming18-Apr-24 0:06
mveRichard Deeming18-Apr-24 0:06 
QuestionWhat is generally the current best method for storing uploaded documents? Pin
we5inelgr6-Mar-24 15:06
we5inelgr6-Mar-24 15:06 
AnswerRe: What is generally the current best method for storing uploaded documents? Pin
Bohdan Stupak7-Mar-24 5:45
professionalBohdan Stupak7-Mar-24 5:45 
GeneralRe: What is generally the current best method for storing uploaded documents? Pin
we5inelgr7-Mar-24 9:05
we5inelgr7-Mar-24 9:05 
GeneralRe: What is generally the current best method for storing uploaded documents? Pin
jschell8-Mar-24 11:40
jschell8-Mar-24 11:40 
AnswerRe: What is generally the current best method for storing uploaded documents? Pin
jschell8-Mar-24 11:47
jschell8-Mar-24 11:47 
AnswerRe: What is generally the current best method for storing uploaded documents? Pin
Andre Oosthuizen9-Mar-24 0:47
mveAndre Oosthuizen9-Mar-24 0:47 
QuestionLooking for a working working sample google maps on blazor web app with loading markers from database Pin
urx194124-Jan-24 23:19
urx194124-Jan-24 23:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.