Var results = await collection.Find(_ => true).ToListAsync().ConfigureAwait(false) Var collection = database.GetCollection (collectionName) Var database = connection.GetDatabase(databaseName) If (() || isSwaggerEnabledFromConfig)Īpp.MapGet("/api/todos", async (MongoClient connection) => Var isSwaggerEnabledFromConfig = (builder.Configuration ? "", StringComparison.OrdinalIgnoreCase) Ĭonsole.WriteLine("Swagger enabled via appsettings.json") String collectionName = ("DocumentCollectionName") ? "ToDos" ī ((_provider) => new MongoClient(connectionString)) String databaseName = ("DocumentDbName") ? "BackendMongoDb" String connectionString = ("DocumentDbConnection") Learn more about configuring Swagger/OpenAPI at ī() Var builder = WebApplication.CreateBuilder(args) NET 6, we can implement a very-simple, still small program to call MongoDB collection and support some basic operations for our API, and we can add Swagger+OpenAPI support with a few lines of code: NET in the /backend: Set up Minimal API for MongoDB NET on the frontend, with the help of amazing Blazor ?✨ 2) Now it’s time for. Also, pretty much of this tutorial can be also take. NET CLI and also Visual Studio provide a great set of pre-defined templates that also include React, Angular and more great stuff, which I encourage to give it a try. Proxy_set_header X-Forwarded-Host $server_name Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for Things will run on their own NGINX-based container so the backend is de-coupled from here.Īdd_header X-XSS-Protection "1 mode=block" Īdd_header Strict-Transport-Security 'max-age=31536000 includeSubDomains preload' Īdd_header X-Content-Type-Options nosniff Īdd_header X-Permitted-Cross-Domain-Policies master-only In order to consume our API later from ASP.NET, let’s add a NGINX file for taking care of the API calls later from our ASP.NET Web API. For this sample, it contains also some files I re-used from Awesome-Compose repo:
Side-note: I didn’t really have to install anything while developing this on my local as I was using GitHub Codespaces with my some tailored devcontainer setup, so I can focus on development! 1) Creating the /frontend: A simple TODO app.įor this sample, we will use react-scripts scaffold for creating a basic app and use a very simple, still classic sample for having a TODO app in order to focus on JavaScript, NodeJS/Npx stuff. So, let’s get started! A few things you may need to install:
The code for this post is also available under my GitHub in this repo: NET 5/6 apps or using GitHub Codespaces for development you can browse them from here and here. If you are interested in previous posts about Awesome-Compose, either curious about Docker-izing. NET in a sample app and ended-up packing it as Pull-Request #248 for the Awesome-Compose repo from Docker in GitHub, following same structure I did for previous. So this time I decided to set a sample to combine React and. I use React the tech behind my blog (mostly NodeJS/Jamstack client-side generated which I migrated recently from existing code that has been around ~2015) both for the client and server side rendering. For this post, I decided to combine them along Compose containers, ASP.NET Minimal APIs and MongoDB support! Using React I’ve been using React for while by mixing it up with.
Published・ Monday, June 20th 2022 Share this post LinkedIn Twitter Facebook Create a React-based app with ASP.NET Minimal APIs and MongoDB storage