o4-mini-2025-04-16· OpenAI
LMArena Human Preference 140K
Write me a simple app with vuejs frontend and c# backend
- User
Write me a simple app with vuejs frontend and c# backend
- Assistant
Here’s a minimal “Todo”‐style app that uses
- a C# /.NET minimal‐API backend
- a Vue 3 (Vite) frontend
It supports CRUD on “todos.”
1) Backend (C#, .NET 7 Minimal API)
- Create a new Web API project:
dotnet new web -o TodoApi cd TodoApi - Edit
Program.csto the following:
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http.Json; using Microsoft.Extensions.DependencyInjection; using System.Collections.Concurrent; var builder = WebApplication.CreateBuilder(args); // Enable CORS for local dev builder.Services.AddCors(options => options.AddDefaultPolicy(p => p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader() ) ); // Use simple in‐memory store var todos = new ConcurrentDictionary<int, TodoItem>(); var nextId = 1; builder.Services.Configure<JsonOptions>(opts => opts.SerializerOptions.PropertyNamingPolicy = null ); var app = builder.Build(); app.UseCors(); // Map endpoints app.MapGet("/api/todos", () => todos.Values); app.MapGet("/api/todos/{id:int}", (int id) => todos.TryGetValue(id, out var todo) ? Results.Ok(todo) : Results.NotFound() ); app.MapPost("/api/todos", (TodoItem input) => { var id = nextId++; input.Id = id; todos[id] = input; return Results.Created($"/api/todos/{id}", input); }); app.MapPut("/api/todos/{id:int}", (int id, TodoItem update) => { if (!todos.ContainsKey(id)) return Results.NotFound(); update.Id = id; todos[id] = update; return Results.NoContent(); }); app.MapDelete("/api/todos/{id:int}", (int id) => todos.TryRemove(id, out _) ? Results.NoContent() : Results.NotFound() ); app.Run(); public record TodoItem { public int Id { get; set; } public string Title { get; set; } = ""; public bool Done { get; set; } }- Run it:
By default it listens ondotnet runhttp://localhost:5000.
2) Frontend (Vue 3 + Vite)
- Scaffold with Vite:
npm init vite@latest todo-vue -- –template vue cd todo-vue npm install - Install Axios for HTTP:
npm install axios - Replace
src/App.vuewith:
<template> <div class="app"> <h1>Vue 3 + .NET Todo</h1> <form @submit.prevent="addTodo"> <input v-model="newTitle" placeholder="New todo…" /> <button type="submit">Add</button> </form> <ul> <li v-for="t in todos" :key="t.id"> <input type="checkbox" v-model="t.done" @change="update(t)" /> <span :class="{ done: t.done }">{{ t.title }}</span> <button @click="remove(t.id)">✕</button> </li> </ul> </div> </template> <script setup> import { ref, onMounted } from 'vue' import axios from 'axios' const API = 'http://localhost:5000/api/todos' const todos = ref([]) const newTitle = ref('') async function fetchTodos() { const { data } = await axios.get(API) todos.value = data } async function addTodo() { const title = newTitle.value.trim() if (!title) return await axios.post(API, { title, done: false }) newTitle.value = '' fetchTodos() } async function update(todo) { await axios.put(`${API}/${todo.id}`, todo) } async function remove(id) { await axios.delete(`${API}/${id}`) fetchTodos() } onMounted(fetchTodos) </script> <style> .app { max-width: 400px; margin: auto; font-family: sans-serif; } .done { text-decoration: line-through; color: #888; } button { margin-left: 0.5em; } input[type="checkbox"] { margin-right: 0.5em; } </style>- Run the frontend:
It’ll spin up atnpm run devhttp://localhost:5173by default.
Now you have a super-simple full-stack Todo app:
- The C# backend serves a JSON API.
- The Vue 3 frontend consumes it via Axios.
Feel free to expand (persist to a DB, add auth, style it, etc.). Enjoy! 🚀
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.