Created
July 31, 2020 16:59
-
-
Save cmatskas/934321cc114439d4fa0f55b0401bac2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System.Collections.Concurrent; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Http; | |
namespace testFeather | |
{ | |
class Program | |
{ | |
private static ConcurrentBag<TodoItem> todoItemCollection; | |
static async Task Main(string[] args) | |
{ | |
var app = WebApplication.Create(args); | |
app.MapGet("/api/todos", GetTodos); | |
app.MapPost("api/todos", CreateTodo); | |
todoItemCollection = new ConcurrentBag<TodoItem>(); | |
await app.RunAsync(); | |
} | |
static async Task CreateTodo(HttpContext http) | |
{ | |
var todo = await http.Request.ReadJsonAsync<TodoItem>(); | |
todoItemCollection.Add(todo); | |
http.Response.StatusCode = 204; | |
} | |
static async Task GetTodos(HttpContext http) | |
{ | |
if(todoItemCollection.Count == 0) | |
{ | |
todoItemCollection.Add( new TodoItem{Id = 1, Name = "test", IsComplete = false}); | |
todoItemCollection.Add(new TodoItem{Id=2, Name="hello", IsComplete=true}); | |
} | |
await http.Response.WriteJsonAsync(todoItemCollection); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment