Created
June 28, 2022 06:19
-
-
Save MelbourneDeveloper/41702ea0051e9dc99635a987ff0e6e7f to your computer and use it in GitHub Desktop.
Protobuf Web API
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
[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"); | |
} | |
[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