Skip to content

Instantly share code, notes, and snippets.

@cmatskas
Created July 31, 2020 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmatskas/934321cc114439d4fa0f55b0401bac2e to your computer and use it in GitHub Desktop.
Save cmatskas/934321cc114439d4fa0f55b0401bac2e to your computer and use it in GitHub Desktop.
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