I have an object that I'm trying to post to my C# API that is just two strings:
Body
Example:
fetch(url, {
method: 'POST',
body: { username: 'myusername', password: 'mypassword' },
headers:{
'Content-Type': 'application/json'
}
});
My API method looks like this:
[HttpPost("auth")]
public async Task<IActionResult>(NetworkCredential creds) { ... }
But, I want it to be this:
[HttpPost("auth")]
public async Task<IActionResult>(string username, string password) { ... }
I really don't want to create a model just for two strings (which is why I'm currently using NetworkCredential
.) I have other instances where it's not username and password so I can't get away with using NetworkCredential
in all cases.
Is there any magic combination/way to setup an API method to sniff out individual strings from the payload without requiring the creation of a model with two properties? I've played around with some of the attributes ([FromBody]
for example) but no luck.