Created
January 10, 2020 21:20
-
-
Save MelbourneDeveloper/eb93507e2e84f092a3458936aac09866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ApiController] | |
[Route("[controller]")] | |
public class PersonController : ControllerBase | |
{ | |
[HttpGet] | |
public IActionResult Get() | |
{ | |
var person = new Person | |
{ | |
FirstName = "Sam", | |
BillingAddress = new Address | |
{ | |
StreeNumber = "100", | |
Street = "Somewhere", | |
Suburb = "Sometown" | |
}, | |
Surname = "Smith" | |
}; | |
var data = person.ToByteArray(); | |
return File(data, "application/octet-stream"); | |
} | |
[HttpPost] | |
public async Task<IActionResult> Post() | |
{ | |
var stream = Request.BodyReader.AsStream(); | |
return File(stream, "application/octet-stream"); | |
} | |
[HttpPut] | |
public async Task<IActionResult> Put() | |
{ | |
var stream = Request.BodyReader.AsStream(); | |
var person = Person.Parser.ParseFrom(stream); | |
if (!Request.Headers.ContainsKey("PersonKey")) throw new Exception("No key"); | |
person.PersonKey = Request.Headers["PersonKey"]; | |
var data = person.ToByteArray(); | |
return File(data, "application/octet-stream"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment