├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── Data └── AppDbContext.cs ├── Migrations ├── 20230724110929_InitialMigration.Designer.cs ├── 20230724110929_InitialMigration.cs └── AppDbContextModelSnapshot.cs ├── Models └── ToDoItem.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Protos ├── greet.proto └── todo.proto ├── Services ├── GreeterService.cs └── ToDoService.cs ├── ToDoDatabase.db ├── ToDoGrpc.csproj ├── appsettings.Development.json ├── appsettings.json └── google └── api ├── annotations.proto └── http.proto /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # Tye 66 | .tye/ 67 | 68 | # ASP.NET Scaffolding 69 | ScaffoldingReadMe.txt 70 | 71 | # StyleCop 72 | StyleCopReport.xml 73 | 74 | # Files built by Visual Studio 75 | *_i.c 76 | *_p.c 77 | *_h.h 78 | *.ilk 79 | *.meta 80 | *.obj 81 | *.iobj 82 | *.pch 83 | *.pdb 84 | *.ipdb 85 | *.pgc 86 | *.pgd 87 | *.rsp 88 | *.sbr 89 | *.tlb 90 | *.tli 91 | *.tlh 92 | *.tmp 93 | *.tmp_proj 94 | *_wpftmp.csproj 95 | *.log 96 | *.tlog 97 | *.vspscc 98 | *.vssscc 99 | .builds 100 | *.pidb 101 | *.svclog 102 | *.scc 103 | 104 | # Chutzpah Test files 105 | _Chutzpah* 106 | 107 | # Visual C++ cache files 108 | ipch/ 109 | *.aps 110 | *.ncb 111 | *.opendb 112 | *.opensdf 113 | *.sdf 114 | *.cachefile 115 | *.VC.db 116 | *.VC.VC.opendb 117 | 118 | # Visual Studio profiler 119 | *.psess 120 | *.vsp 121 | *.vspx 122 | *.sap 123 | 124 | # Visual Studio Trace Files 125 | *.e2e 126 | 127 | # TFS 2012 Local Workspace 128 | $tf/ 129 | 130 | # Guidance Automation Toolkit 131 | *.gpState 132 | 133 | # ReSharper is a .NET coding add-in 134 | _ReSharper*/ 135 | *.[Rr]e[Ss]harper 136 | *.DotSettings.user 137 | 138 | # TeamCity is a build add-in 139 | _TeamCity* 140 | 141 | # DotCover is a Code Coverage Tool 142 | *.dotCover 143 | 144 | # AxoCover is a Code Coverage Tool 145 | .axoCover/* 146 | !.axoCover/settings.json 147 | 148 | # Coverlet is a free, cross platform Code Coverage Tool 149 | coverage*.json 150 | coverage*.xml 151 | coverage*.info 152 | 153 | # Visual Studio code coverage results 154 | *.coverage 155 | *.coveragexml 156 | 157 | # NCrunch 158 | _NCrunch_* 159 | .*crunch*.local.xml 160 | nCrunchTemp_* 161 | 162 | # MightyMoose 163 | *.mm.* 164 | AutoTest.Net/ 165 | 166 | # Web workbench (sass) 167 | .sass-cache/ 168 | 169 | # Installshield output folder 170 | [Ee]xpress/ 171 | 172 | # DocProject is a documentation generator add-in 173 | DocProject/buildhelp/ 174 | DocProject/Help/*.HxT 175 | DocProject/Help/*.HxC 176 | DocProject/Help/*.hhc 177 | DocProject/Help/*.hhk 178 | DocProject/Help/*.hhp 179 | DocProject/Help/Html2 180 | DocProject/Help/html 181 | 182 | # Click-Once directory 183 | publish/ 184 | 185 | # Publish Web Output 186 | *.[Pp]ublish.xml 187 | *.azurePubxml 188 | # Note: Comment the next line if you want to checkin your web deploy settings, 189 | # but database connection strings (with potential passwords) will be unencrypted 190 | *.pubxml 191 | *.publishproj 192 | 193 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 194 | # checkin your Azure Web App publish settings, but sensitive information contained 195 | # in these scripts will be unencrypted 196 | PublishScripts/ 197 | 198 | # NuGet Packages 199 | *.nupkg 200 | # NuGet Symbol Packages 201 | *.snupkg 202 | # The packages folder can be ignored because of Package Restore 203 | **/[Pp]ackages/* 204 | # except build/, which is used as an MSBuild target. 205 | !**/[Pp]ackages/build/ 206 | # Uncomment if necessary however generally it will be regenerated when needed 207 | #!**/[Pp]ackages/repositories.config 208 | # NuGet v3's project.json files produces more ignorable files 209 | *.nuget.props 210 | *.nuget.targets 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 301 | *.vbp 302 | 303 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 304 | *.dsw 305 | *.dsp 306 | 307 | # Visual Studio 6 technical files 308 | *.ncb 309 | *.aps 310 | 311 | # Visual Studio LightSwitch build output 312 | **/*.HTMLClient/GeneratedArtifacts 313 | **/*.DesktopClient/GeneratedArtifacts 314 | **/*.DesktopClient/ModelManifest.xml 315 | **/*.Server/GeneratedArtifacts 316 | **/*.Server/ModelManifest.xml 317 | _Pvt_Extensions 318 | 319 | # Paket dependency manager 320 | .paket/paket.exe 321 | paket-files/ 322 | 323 | # FAKE - F# Make 324 | .fake/ 325 | 326 | # CodeRush personal settings 327 | .cr/personal 328 | 329 | # Python Tools for Visual Studio (PTVS) 330 | __pycache__/ 331 | *.pyc 332 | 333 | # Cake - Uncomment if you are using it 334 | # tools/** 335 | # !tools/packages.config 336 | 337 | # Tabs Studio 338 | *.tss 339 | 340 | # Telerik's JustMock configuration file 341 | *.jmconfig 342 | 343 | # BizTalk build output 344 | *.btp.cs 345 | *.btm.cs 346 | *.odx.cs 347 | *.xsd.cs 348 | 349 | # OpenCover UI analysis results 350 | OpenCover/ 351 | 352 | # Azure Stream Analytics local run output 353 | ASALocalRun/ 354 | 355 | # MSBuild Binary and Structured Log 356 | *.binlog 357 | 358 | # NVidia Nsight GPU debugger configuration file 359 | *.nvuser 360 | 361 | # MFractors (Xamarin productivity tool) working folder 362 | .mfractor/ 363 | 364 | # Local History for Visual Studio 365 | .localhistory/ 366 | 367 | # Visual Studio History (VSHistory) files 368 | .vshistory/ 369 | 370 | # BeatPulse healthcheck temp database 371 | healthchecksdb 372 | 373 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 374 | MigrationBackup/ 375 | 376 | # Ionide (cross platform F# VS Code tools) working folder 377 | .ionide/ 378 | 379 | # Fody - auto-generated XML schema 380 | FodyWeavers.xsd 381 | 382 | # VS Code files for those working on multiple tools 383 | .vscode/* 384 | !.vscode/settings.json 385 | !.vscode/tasks.json 386 | !.vscode/launch.json 387 | !.vscode/extensions.json 388 | *.code-workspace 389 | 390 | # Local History for Visual Studio Code 391 | .history/ 392 | 393 | # Windows Installer files from build outputs 394 | *.cab 395 | *.msi 396 | *.msix 397 | *.msm 398 | *.msp 399 | 400 | # JetBrains Rider 401 | *.sln.iml 402 | 403 | ## 404 | ## Visual studio for Mac 405 | ## 406 | 407 | 408 | # globs 409 | Makefile.in 410 | *.userprefs 411 | *.usertasks 412 | config.make 413 | config.status 414 | aclocal.m4 415 | install-sh 416 | autom4te.cache/ 417 | *.tar.gz 418 | tarballs/ 419 | test-results/ 420 | 421 | # Mac bundle stuff 422 | *.dmg 423 | *.app 424 | 425 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore 426 | # General 427 | .DS_Store 428 | .AppleDouble 429 | .LSOverride 430 | 431 | # Icon must end with two \r 432 | Icon 433 | 434 | 435 | # Thumbnails 436 | ._* 437 | 438 | # Files that might appear in the root of a volume 439 | .DocumentRevisions-V100 440 | .fseventsd 441 | .Spotlight-V100 442 | .TemporaryItems 443 | .Trashes 444 | .VolumeIcon.icns 445 | .com.apple.timemachine.donotpresent 446 | 447 | # Directories potentially created on remote AFP share 448 | .AppleDB 449 | .AppleDesktop 450 | Network Trash Folder 451 | Temporary Items 452 | .apdisk 453 | 454 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore 455 | # Windows thumbnail cache files 456 | Thumbs.db 457 | ehthumbs.db 458 | ehthumbs_vista.db 459 | 460 | # Dump file 461 | *.stackdump 462 | 463 | # Folder config file 464 | [Dd]esktop.ini 465 | 466 | # Recycle Bin used on file shares 467 | $RECYCLE.BIN/ 468 | 469 | # Windows Installer files 470 | *.cab 471 | *.msi 472 | *.msix 473 | *.msm 474 | *.msp 475 | 476 | # Windows shortcuts 477 | *.lnk 478 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | // Use IntelliSense to find out which attributes exist for C# debugging 6 | // Use hover for the description of the existing attributes 7 | // For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md 8 | "name": ".NET Core Launch (web)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/bin/Debug/net7.0/ToDoGrpc.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}", 16 | "stopAtEntry": false, 17 | // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser 18 | "serverReadyAction": { 19 | "action": "openExternally", 20 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)" 21 | }, 22 | "env": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "sourceFileMap": { 26 | "/Views": "${workspaceFolder}/Views" 27 | } 28 | }, 29 | { 30 | "name": ".NET Core Attach", 31 | "type": "coreclr", 32 | "request": "attach" 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/ToDoGrpc.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/ToDoGrpc.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "--project", 36 | "${workspaceFolder}/ToDoGrpc.csproj" 37 | ], 38 | "problemMatcher": "$msCompile" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /Data/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using ToDoGrpc.Models; 3 | 4 | namespace ToDoGrpc.Data; 5 | 6 | public class AppDbContext : DbContext 7 | { 8 | public AppDbContext(DbContextOptions options) : base(options) 9 | { 10 | 11 | } 12 | 13 | public DbSet ToDoItems => Set(); 14 | } -------------------------------------------------------------------------------- /Migrations/20230724110929_InitialMigration.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Migrations; 5 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 6 | using ToDoGrpc.Data; 7 | 8 | #nullable disable 9 | 10 | namespace ToDoGrpc.Migrations 11 | { 12 | [DbContext(typeof(AppDbContext))] 13 | [Migration("20230724110929_InitialMigration")] 14 | partial class InitialMigration 15 | { 16 | /// 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder.HasAnnotation("ProductVersion", "7.0.9"); 21 | 22 | modelBuilder.Entity("ToDoGrpc.Models.ToDoItem", b => 23 | { 24 | b.Property("Id") 25 | .ValueGeneratedOnAdd() 26 | .HasColumnType("INTEGER"); 27 | 28 | b.Property("Description") 29 | .HasColumnType("TEXT"); 30 | 31 | b.Property("Title") 32 | .HasColumnType("TEXT"); 33 | 34 | b.Property("ToDoStatus") 35 | .IsRequired() 36 | .HasColumnType("TEXT"); 37 | 38 | b.HasKey("Id"); 39 | 40 | b.ToTable("ToDoItems"); 41 | }); 42 | #pragma warning restore 612, 618 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Migrations/20230724110929_InitialMigration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace ToDoGrpc.Migrations 6 | { 7 | /// 8 | public partial class InitialMigration : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.CreateTable( 14 | name: "ToDoItems", 15 | columns: table => new 16 | { 17 | Id = table.Column(type: "INTEGER", nullable: false) 18 | .Annotation("Sqlite:Autoincrement", true), 19 | Title = table.Column(type: "TEXT", nullable: true), 20 | Description = table.Column(type: "TEXT", nullable: true), 21 | ToDoStatus = table.Column(type: "TEXT", nullable: false) 22 | }, 23 | constraints: table => 24 | { 25 | table.PrimaryKey("PK_ToDoItems", x => x.Id); 26 | }); 27 | } 28 | 29 | /// 30 | protected override void Down(MigrationBuilder migrationBuilder) 31 | { 32 | migrationBuilder.DropTable( 33 | name: "ToDoItems"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Migrations/AppDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 5 | using ToDoGrpc.Data; 6 | 7 | #nullable disable 8 | 9 | namespace ToDoGrpc.Migrations 10 | { 11 | [DbContext(typeof(AppDbContext))] 12 | partial class AppDbContextModelSnapshot : ModelSnapshot 13 | { 14 | protected override void BuildModel(ModelBuilder modelBuilder) 15 | { 16 | #pragma warning disable 612, 618 17 | modelBuilder.HasAnnotation("ProductVersion", "7.0.9"); 18 | 19 | modelBuilder.Entity("ToDoGrpc.Models.ToDoItem", b => 20 | { 21 | b.Property("Id") 22 | .ValueGeneratedOnAdd() 23 | .HasColumnType("INTEGER"); 24 | 25 | b.Property("Description") 26 | .HasColumnType("TEXT"); 27 | 28 | b.Property("Title") 29 | .HasColumnType("TEXT"); 30 | 31 | b.Property("ToDoStatus") 32 | .IsRequired() 33 | .HasColumnType("TEXT"); 34 | 35 | b.HasKey("Id"); 36 | 37 | b.ToTable("ToDoItems"); 38 | }); 39 | #pragma warning restore 612, 618 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Models/ToDoItem.cs: -------------------------------------------------------------------------------- 1 | namespace ToDoGrpc.Models; 2 | 3 | public class ToDoItem 4 | { 5 | public int Id { get; set; } 6 | 7 | public string? Title { get; set; } 8 | 9 | public string? Description { get; set; } 10 | 11 | public string ToDoStatus { get; set; } = "NEW"; 12 | } -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using ToDoGrpc.Data; 3 | using ToDoGrpc.Services; 4 | 5 | var builder = WebApplication.CreateBuilder(args); 6 | 7 | builder.Services.AddDbContext(opt => opt.UseSqlite("Data Source=ToDoDatabase.db")); 8 | 9 | builder.Services.AddGrpc().AddJsonTranscoding(); 10 | 11 | var app = builder.Build(); 12 | 13 | 14 | app.MapGrpcService(); 15 | app.MapGrpcService(); 16 | 17 | app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); 18 | 19 | app.Run(); 20 | -------------------------------------------------------------------------------- /Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "https": { 4 | "commandName": "Project", 5 | "dotnetRunMessages": true, 6 | "launchBrowser": false, 7 | "applicationUrl": "https://localhost:7175;http://localhost:5066", 8 | "environmentVariables": { 9 | "ASPNETCORE_ENVIRONMENT": "Development" 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Protos/greet.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option csharp_namespace = "ToDoGrpc"; 4 | 5 | package greet; 6 | 7 | // The greeting service definition. 8 | service Greeter { 9 | // Sends a greeting 10 | rpc SayHello (HelloRequest) returns (HelloReply); 11 | } 12 | 13 | // The request message containing the user's name. 14 | message HelloRequest { 15 | string name = 1; 16 | } 17 | 18 | // The response message containing the greetings. 19 | message HelloReply { 20 | string message = 1; 21 | } 22 | -------------------------------------------------------------------------------- /Protos/todo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option csharp_namespace = "ToDoGrpc"; 4 | 5 | import "google/api/annotations.proto"; 6 | 7 | package todoit; 8 | 9 | service ToDoIt { 10 | // Create 11 | rpc CreateToDo(CreateToDoRequest) returns (CreateToDoResponse) { 12 | option (google.api.http) = { 13 | post: "/v1/todo", 14 | body: "*" 15 | }; 16 | } 17 | 18 | // Read single 19 | rpc ReadToDo(ReadToDoRequest) returns (ReadToDoResponse) { 20 | option (google.api.http) = { 21 | get: "/v1/todo/{id}" 22 | }; 23 | } 24 | 25 | // Read list 26 | rpc ListToDo(GetAllRequest) returns (GetAllResponse) { 27 | option (google.api.http) = { 28 | get: "/v1/todo" 29 | }; 30 | } 31 | 32 | // Update 33 | rpc UpdateToDo (UpdateToDoRequest) returns (UpdateToDoResponse) { 34 | option (google.api.http) = { 35 | put : "/v1/todo", 36 | body: "*" 37 | }; 38 | } 39 | 40 | // Delete 41 | rpc DeleteToDo (DeleteToDoRequest) returns (DeleteToDoResponse) { 42 | option (google.api.http) = { 43 | delete: "/v1/todo/{id}" 44 | }; 45 | } 46 | } 47 | 48 | message CreateToDoRequest { 49 | string title = 1; 50 | string description = 2; 51 | } 52 | 53 | message CreateToDoResponse { 54 | int32 id = 1; 55 | } 56 | 57 | message ReadToDoRequest { 58 | int32 id = 1; 59 | } 60 | 61 | message ReadToDoResponse { 62 | int32 id = 1; 63 | string title = 2; 64 | string description = 3; 65 | string to_do_status = 4; 66 | } 67 | 68 | message GetAllRequest {} 69 | 70 | message GetAllResponse { 71 | repeated ReadToDoResponse to_do = 1; 72 | } 73 | 74 | message UpdateToDoRequest { 75 | int32 id = 1; 76 | string title = 2; 77 | string description = 3; 78 | string to_do_status = 4; 79 | } 80 | 81 | message UpdateToDoResponse { 82 | int32 id = 1; 83 | } 84 | 85 | message DeleteToDoRequest { 86 | int32 id = 1; 87 | } 88 | 89 | message DeleteToDoResponse { 90 | int32 id = 1; 91 | } -------------------------------------------------------------------------------- /Services/GreeterService.cs: -------------------------------------------------------------------------------- 1 | using Grpc.Core; 2 | using ToDoGrpc; 3 | 4 | namespace ToDoGrpc.Services; 5 | 6 | public class GreeterService : Greeter.GreeterBase 7 | { 8 | private readonly ILogger _logger; 9 | public GreeterService(ILogger logger) 10 | { 11 | _logger = logger; 12 | } 13 | 14 | public override Task SayHello(HelloRequest request, ServerCallContext context) 15 | { 16 | return Task.FromResult(new HelloReply 17 | { 18 | Message = "Hello " + request.Name 19 | }); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Services/ToDoService.cs: -------------------------------------------------------------------------------- 1 | using Grpc.Core; 2 | using Microsoft.EntityFrameworkCore; 3 | using ToDoGrpc.Data; 4 | using ToDoGrpc.Models; 5 | 6 | namespace ToDoGrpc.Services; 7 | 8 | public class ToDoService : ToDoIt.ToDoItBase 9 | { 10 | private readonly AppDbContext _dbContext; 11 | 12 | public ToDoService(AppDbContext dbContext) 13 | { 14 | _dbContext = dbContext; 15 | } 16 | 17 | public override async Task CreateToDo(CreateToDoRequest request, ServerCallContext context) 18 | { 19 | if(request.Title == string.Empty || request.Description == string.Empty) 20 | throw new RpcException(new Status(StatusCode.InvalidArgument, "You must suppply a valid object")); 21 | 22 | var toDoItem = new ToDoItem 23 | { 24 | Title = request.Title, 25 | Description = request.Description 26 | }; 27 | 28 | await _dbContext.AddAsync(toDoItem); 29 | await _dbContext.SaveChangesAsync(); 30 | 31 | return await Task.FromResult(new CreateToDoResponse 32 | { 33 | Id = toDoItem.Id 34 | }); 35 | } 36 | 37 | public override async Task ReadToDo(ReadToDoRequest request, ServerCallContext context) 38 | { 39 | if(request.Id <=0) 40 | throw new RpcException(new Status(StatusCode.InvalidArgument, "resouce index must be greater than 0")); 41 | 42 | var toDoItem = await _dbContext.ToDoItems.FirstOrDefaultAsync(t=>t.Id == request.Id); 43 | 44 | if(toDoItem != null) 45 | { 46 | return await Task.FromResult(new ReadToDoResponse{ 47 | Id = toDoItem.Id, 48 | Title = toDoItem.Title, 49 | Description = toDoItem.Description, 50 | ToDoStatus = toDoItem.ToDoStatus 51 | }); 52 | } 53 | 54 | throw new RpcException(new Status(StatusCode.NotFound, $"No Task with id {request.Id}")); 55 | } 56 | 57 | public override async Task ListToDo(GetAllRequest request, ServerCallContext context) 58 | { 59 | var response = new GetAllResponse(); 60 | var toDoItems = await _dbContext.ToDoItems.ToListAsync(); 61 | 62 | foreach(var toDo in toDoItems) 63 | { 64 | response.ToDo.Add(new ReadToDoResponse{ 65 | Id = toDo.Id, 66 | Title = toDo.Title, 67 | Description = toDo.Description, 68 | ToDoStatus = toDo.ToDoStatus 69 | }); 70 | } 71 | 72 | return await Task.FromResult(response); 73 | } 74 | 75 | public override async Task UpdateToDo(UpdateToDoRequest request, ServerCallContext context) 76 | { 77 | if(request.Id <= 0 || request.Title == string.Empty || request.Description == string.Empty ) 78 | throw new RpcException(new Status(StatusCode.InvalidArgument, "You must suppply a valid object")); 79 | 80 | var toDoItem = await _dbContext.ToDoItems.FirstOrDefaultAsync(t=>t.Id == request.Id); 81 | 82 | if(toDoItem == null) 83 | throw new RpcException(new Status(StatusCode.NotFound, $"No Task with Id {request.Id}")); 84 | 85 | toDoItem.Title = request.Title; 86 | toDoItem.Description = request.Description; 87 | toDoItem.ToDoStatus = request.ToDoStatus; 88 | 89 | await _dbContext.SaveChangesAsync(); 90 | 91 | return await Task.FromResult(new UpdateToDoResponse{ 92 | Id = toDoItem.Id 93 | }); 94 | } 95 | 96 | public override async Task DeleteToDo(DeleteToDoRequest request, ServerCallContext context) 97 | { 98 | if(request.Id <=0) 99 | throw new RpcException(new Status(StatusCode.InvalidArgument, "resouce index must be greater than 0")); 100 | 101 | var toDoItem = await _dbContext.ToDoItems.FirstOrDefaultAsync(t=>t.Id == request.Id); 102 | 103 | if(toDoItem == null) 104 | throw new RpcException(new Status(StatusCode.NotFound, $"No Task with Id {request.Id}")); 105 | 106 | _dbContext.Remove(toDoItem); 107 | 108 | await _dbContext.SaveChangesAsync(); 109 | 110 | return await Task.FromResult(new DeleteToDoResponse{ 111 | Id = toDoItem.Id 112 | }); 113 | 114 | } 115 | } -------------------------------------------------------------------------------- /ToDoDatabase.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binarythistle/S06E04-Build-a-gRPC-service-in-NET-7/7734a162dd2f5014ef0e849d2c5bc1a80b52ff93/ToDoDatabase.db -------------------------------------------------------------------------------- /ToDoGrpc.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | all 19 | 20 | 21 | 22 | runtime; build; native; contentfiles; analyzers; buildtransitive 23 | all 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "Kestrel": { 10 | "EndpointDefaults": { 11 | "Protocols": "Http1AndHttp2" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } -------------------------------------------------------------------------------- /google/api/http.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | syntax = "proto3"; 17 | 18 | package google.api; 19 | 20 | option cc_enable_arenas = true; 21 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 22 | option java_multiple_files = true; 23 | option java_outer_classname = "HttpProto"; 24 | option java_package = "com.google.api"; 25 | option objc_class_prefix = "GAPI"; 26 | 27 | // Defines the HTTP configuration for an API service. It contains a list of 28 | // [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method 29 | // to one or more HTTP REST API methods. 30 | message Http { 31 | // A list of HTTP configuration rules that apply to individual API methods. 32 | // 33 | // **NOTE:** All service configuration rules follow "last one wins" order. 34 | repeated HttpRule rules = 1; 35 | 36 | // When set to true, URL path parameters will be fully URI-decoded except in 37 | // cases of single segment matches in reserved expansion, where "%2F" will be 38 | // left encoded. 39 | // 40 | // The default behavior is to not decode RFC 6570 reserved characters in multi 41 | // segment matches. 42 | bool fully_decode_reserved_expansion = 2; 43 | } 44 | 45 | // # gRPC Transcoding 46 | // 47 | // gRPC Transcoding is a feature for mapping between a gRPC method and one or 48 | // more HTTP REST endpoints. It allows developers to build a single API service 49 | // that supports both gRPC APIs and REST APIs. Many systems, including [Google 50 | // APIs](https://github.com/googleapis/googleapis), 51 | // [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC 52 | // Gateway](https://github.com/grpc-ecosystem/grpc-gateway), 53 | // and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature 54 | // and use it for large scale production services. 55 | // 56 | // `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies 57 | // how different portions of the gRPC request message are mapped to the URL 58 | // path, URL query parameters, and HTTP request body. It also controls how the 59 | // gRPC response message is mapped to the HTTP response body. `HttpRule` is 60 | // typically specified as an `google.api.http` annotation on the gRPC method. 61 | // 62 | // Each mapping specifies a URL path template and an HTTP method. The path 63 | // template may refer to one or more fields in the gRPC request message, as long 64 | // as each field is a non-repeated field with a primitive (non-message) type. 65 | // The path template controls how fields of the request message are mapped to 66 | // the URL path. 67 | // 68 | // Example: 69 | // 70 | // service Messaging { 71 | // rpc GetMessage(GetMessageRequest) returns (Message) { 72 | // option (google.api.http) = { 73 | // get: "/v1/{name=messages/*}" 74 | // }; 75 | // } 76 | // } 77 | // message GetMessageRequest { 78 | // string name = 1; // Mapped to URL path. 79 | // } 80 | // message Message { 81 | // string text = 1; // The resource content. 82 | // } 83 | // 84 | // This enables an HTTP REST to gRPC mapping as below: 85 | // 86 | // HTTP | gRPC 87 | // -----|----- 88 | // `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` 89 | // 90 | // Any fields in the request message which are not bound by the path template 91 | // automatically become HTTP query parameters if there is no HTTP request body. 92 | // For example: 93 | // 94 | // service Messaging { 95 | // rpc GetMessage(GetMessageRequest) returns (Message) { 96 | // option (google.api.http) = { 97 | // get:"/v1/messages/{message_id}" 98 | // }; 99 | // } 100 | // } 101 | // message GetMessageRequest { 102 | // message SubMessage { 103 | // string subfield = 1; 104 | // } 105 | // string message_id = 1; // Mapped to URL path. 106 | // int64 revision = 2; // Mapped to URL query parameter `revision`. 107 | // SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. 108 | // } 109 | // 110 | // This enables a HTTP JSON to RPC mapping as below: 111 | // 112 | // HTTP | gRPC 113 | // -----|----- 114 | // `GET /v1/messages/123456?revision=2&sub.subfield=foo` | 115 | // `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: 116 | // "foo"))` 117 | // 118 | // Note that fields which are mapped to URL query parameters must have a 119 | // primitive type or a repeated primitive type or a non-repeated message type. 120 | // In the case of a repeated type, the parameter can be repeated in the URL 121 | // as `...?param=A¶m=B`. In the case of a message type, each field of the 122 | // message is mapped to a separate parameter, such as 123 | // `...?foo.a=A&foo.b=B&foo.c=C`. 124 | // 125 | // For HTTP methods that allow a request body, the `body` field 126 | // specifies the mapping. Consider a REST update method on the 127 | // message resource collection: 128 | // 129 | // service Messaging { 130 | // rpc UpdateMessage(UpdateMessageRequest) returns (Message) { 131 | // option (google.api.http) = { 132 | // patch: "/v1/messages/{message_id}" 133 | // body: "message" 134 | // }; 135 | // } 136 | // } 137 | // message UpdateMessageRequest { 138 | // string message_id = 1; // mapped to the URL 139 | // Message message = 2; // mapped to the body 140 | // } 141 | // 142 | // The following HTTP JSON to RPC mapping is enabled, where the 143 | // representation of the JSON in the request body is determined by 144 | // protos JSON encoding: 145 | // 146 | // HTTP | gRPC 147 | // -----|----- 148 | // `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: 149 | // "123456" message { text: "Hi!" })` 150 | // 151 | // The special name `*` can be used in the body mapping to define that 152 | // every field not bound by the path template should be mapped to the 153 | // request body. This enables the following alternative definition of 154 | // the update method: 155 | // 156 | // service Messaging { 157 | // rpc UpdateMessage(Message) returns (Message) { 158 | // option (google.api.http) = { 159 | // patch: "/v1/messages/{message_id}" 160 | // body: "*" 161 | // }; 162 | // } 163 | // } 164 | // message Message { 165 | // string message_id = 1; 166 | // string text = 2; 167 | // } 168 | // 169 | // 170 | // The following HTTP JSON to RPC mapping is enabled: 171 | // 172 | // HTTP | gRPC 173 | // -----|----- 174 | // `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: 175 | // "123456" text: "Hi!")` 176 | // 177 | // Note that when using `*` in the body mapping, it is not possible to 178 | // have HTTP parameters, as all fields not bound by the path end in 179 | // the body. This makes this option more rarely used in practice when 180 | // defining REST APIs. The common usage of `*` is in custom methods 181 | // which don't use the URL at all for transferring data. 182 | // 183 | // It is possible to define multiple HTTP methods for one RPC by using 184 | // the `additional_bindings` option. Example: 185 | // 186 | // service Messaging { 187 | // rpc GetMessage(GetMessageRequest) returns (Message) { 188 | // option (google.api.http) = { 189 | // get: "/v1/messages/{message_id}" 190 | // additional_bindings { 191 | // get: "/v1/users/{user_id}/messages/{message_id}" 192 | // } 193 | // }; 194 | // } 195 | // } 196 | // message GetMessageRequest { 197 | // string message_id = 1; 198 | // string user_id = 2; 199 | // } 200 | // 201 | // This enables the following two alternative HTTP JSON to RPC mappings: 202 | // 203 | // HTTP | gRPC 204 | // -----|----- 205 | // `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` 206 | // `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: 207 | // "123456")` 208 | // 209 | // ## Rules for HTTP mapping 210 | // 211 | // 1. Leaf request fields (recursive expansion nested messages in the request 212 | // message) are classified into three categories: 213 | // - Fields referred by the path template. They are passed via the URL path. 214 | // - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They are passed via the HTTP 215 | // request body. 216 | // - All other fields are passed via the URL query parameters, and the 217 | // parameter name is the field path in the request message. A repeated 218 | // field can be represented as multiple query parameters under the same 219 | // name. 220 | // 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL query parameter, all fields 221 | // are passed via URL path and HTTP request body. 222 | // 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP request body, all 223 | // fields are passed via URL path and URL query parameters. 224 | // 225 | // ### Path template syntax 226 | // 227 | // Template = "/" Segments [ Verb ] ; 228 | // Segments = Segment { "/" Segment } ; 229 | // Segment = "*" | "**" | LITERAL | Variable ; 230 | // Variable = "{" FieldPath [ "=" Segments ] "}" ; 231 | // FieldPath = IDENT { "." IDENT } ; 232 | // Verb = ":" LITERAL ; 233 | // 234 | // The syntax `*` matches a single URL path segment. The syntax `**` matches 235 | // zero or more URL path segments, which must be the last part of the URL path 236 | // except the `Verb`. 237 | // 238 | // The syntax `Variable` matches part of the URL path as specified by its 239 | // template. A variable template must not contain other variables. If a variable 240 | // matches a single path segment, its template may be omitted, e.g. `{var}` 241 | // is equivalent to `{var=*}`. 242 | // 243 | // The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` 244 | // contains any reserved character, such characters should be percent-encoded 245 | // before the matching. 246 | // 247 | // If a variable contains exactly one path segment, such as `"{var}"` or 248 | // `"{var=*}"`, when such a variable is expanded into a URL path on the client 249 | // side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The 250 | // server side does the reverse decoding. Such variables show up in the 251 | // [Discovery 252 | // Document](https://developers.google.com/discovery/v1/reference/apis) as 253 | // `{var}`. 254 | // 255 | // If a variable contains multiple path segments, such as `"{var=foo/*}"` 256 | // or `"{var=**}"`, when such a variable is expanded into a URL path on the 257 | // client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. 258 | // The server side does the reverse decoding, except "%2F" and "%2f" are left 259 | // unchanged. Such variables show up in the 260 | // [Discovery 261 | // Document](https://developers.google.com/discovery/v1/reference/apis) as 262 | // `{+var}`. 263 | // 264 | // ## Using gRPC API Service Configuration 265 | // 266 | // gRPC API Service Configuration (service config) is a configuration language 267 | // for configuring a gRPC service to become a user-facing product. The 268 | // service config is simply the YAML representation of the `google.api.Service` 269 | // proto message. 270 | // 271 | // As an alternative to annotating your proto file, you can configure gRPC 272 | // transcoding in your service config YAML files. You do this by specifying a 273 | // `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same 274 | // effect as the proto annotation. This can be particularly useful if you 275 | // have a proto that is reused in multiple services. Note that any transcoding 276 | // specified in the service config will override any matching transcoding 277 | // configuration in the proto. 278 | // 279 | // Example: 280 | // 281 | // http: 282 | // rules: 283 | // # Selects a gRPC method and applies HttpRule to it. 284 | // - selector: example.v1.Messaging.GetMessage 285 | // get: /v1/messages/{message_id}/{sub.subfield} 286 | // 287 | // ## Special notes 288 | // 289 | // When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the 290 | // proto to JSON conversion must follow the [proto3 291 | // specification](https://developers.google.com/protocol-buffers/docs/proto3#json). 292 | // 293 | // While the single segment variable follows the semantics of 294 | // [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String 295 | // Expansion, the multi segment variable **does not** follow RFC 6570 Section 296 | // 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion 297 | // does not expand special characters like `?` and `#`, which would lead 298 | // to invalid URLs. As the result, gRPC Transcoding uses a custom encoding 299 | // for multi segment variables. 300 | // 301 | // The path variables **must not** refer to any repeated or mapped field, 302 | // because client libraries are not capable of handling such variable expansion. 303 | // 304 | // The path variables **must not** capture the leading "/" character. The reason 305 | // is that the most common use case "{var}" does not capture the leading "/" 306 | // character. For consistency, all path variables must share the same behavior. 307 | // 308 | // Repeated message fields must not be mapped to URL query parameters, because 309 | // no client library can support such complicated mapping. 310 | // 311 | // If an API needs to use a JSON array for request or response body, it can map 312 | // the request or response body to a repeated field. However, some gRPC 313 | // Transcoding implementations may not support this feature. 314 | message HttpRule { 315 | // Selects a method to which this rule applies. 316 | // 317 | // Refer to [selector][google.api.DocumentationRule.selector] for syntax details. 318 | string selector = 1; 319 | 320 | // Determines the URL pattern is matched by this rules. This pattern can be 321 | // used with any of the {get|put|post|delete|patch} methods. A custom method 322 | // can be defined using the 'custom' field. 323 | oneof pattern { 324 | // Maps to HTTP GET. Used for listing and getting information about 325 | // resources. 326 | string get = 2; 327 | 328 | // Maps to HTTP PUT. Used for replacing a resource. 329 | string put = 3; 330 | 331 | // Maps to HTTP POST. Used for creating a resource or performing an action. 332 | string post = 4; 333 | 334 | // Maps to HTTP DELETE. Used for deleting a resource. 335 | string delete = 5; 336 | 337 | // Maps to HTTP PATCH. Used for updating a resource. 338 | string patch = 6; 339 | 340 | // The custom pattern is used for specifying an HTTP method that is not 341 | // included in the `pattern` field, such as HEAD, or "*" to leave the 342 | // HTTP method unspecified for this rule. The wild-card rule is useful 343 | // for services that provide content to Web (HTML) clients. 344 | CustomHttpPattern custom = 8; 345 | } 346 | 347 | // The name of the request field whose value is mapped to the HTTP request 348 | // body, or `*` for mapping all request fields not captured by the path 349 | // pattern to the HTTP body, or omitted for not having any HTTP request body. 350 | // 351 | // NOTE: the referred field must be present at the top-level of the request 352 | // message type. 353 | string body = 7; 354 | 355 | // Optional. The name of the response field whose value is mapped to the HTTP 356 | // response body. When omitted, the entire response message will be used 357 | // as the HTTP response body. 358 | // 359 | // NOTE: The referred field must be present at the top-level of the response 360 | // message type. 361 | string response_body = 12; 362 | 363 | // Additional HTTP bindings for the selector. Nested bindings must 364 | // not contain an `additional_bindings` field themselves (that is, 365 | // the nesting may only be one level deep). 366 | repeated HttpRule additional_bindings = 11; 367 | } 368 | 369 | // A custom pattern is used for defining custom HTTP verb. 370 | message CustomHttpPattern { 371 | // The name of this custom HTTP verb. 372 | string kind = 1; 373 | 374 | // The path matched by this custom verb. 375 | string path = 2; 376 | } 377 | --------------------------------------------------------------------------------