Last active
September 15, 2018 08:29
-
-
Save amsokol/57cd11e08b07542837fdbaa596864b5c to your computer and use it in GitHub Desktop.
(gRPC+REST) todo-service.proto
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
syntax = "proto3"; | |
package v1; | |
import "google/protobuf/timestamp.proto"; | |
import "google/api/annotations.proto"; | |
import "protoc-gen-swagger/options/annotations.proto"; | |
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = { | |
info: { | |
title: "ToDo service"; | |
version: "1.0"; | |
contact: { | |
name: "go-grpc-http-rest-microservice-tutorial project"; | |
url: "https://github.com/amsokol/go-grpc-http-rest-microservice-tutorial"; | |
email: "[email protected]"; | |
}; | |
}; | |
schemes: HTTP; | |
consumes: "application/json"; | |
produces: "application/json"; | |
responses: { | |
key: "404"; | |
value: { | |
description: "Returned when the resource does not exist."; | |
schema: { | |
json_schema: { | |
type: STRING; | |
} | |
} | |
} | |
} | |
}; | |
// Task we have to do | |
message ToDo { | |
// Unique integer identifier of the todo task | |
int64 id = 1; | |
// Title of the task | |
string title = 2; | |
// Detail description of the todo task | |
string description = 3; | |
// Date and time to remind the todo task | |
google.protobuf.Timestamp reminder = 4; | |
} | |
// Request data to create new todo task | |
message CreateRequest{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
// Task entity to add | |
ToDo toDo = 2; | |
} | |
// Contains data of created todo task | |
message CreateResponse{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
// ID of created task | |
int64 id = 2; | |
} | |
// Request data to read todo task | |
message ReadRequest{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
// Unique integer identifier of the todo task | |
int64 id = 2; | |
} | |
// Contains todo task data specified in by ID request | |
message ReadResponse{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
// Task entity read by ID | |
ToDo toDo = 2; | |
} | |
// Request data to update todo task | |
message UpdateRequest{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
// Task entity to update | |
ToDo toDo = 2; | |
} | |
// Contains status of update operation | |
message UpdateResponse{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
// Contains number of entities have beed updated | |
// Equals 1 in case of succesfull update | |
int64 updated = 2; | |
} | |
// Request data to delete todo task | |
message DeleteRequest{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
// Unique integer identifier of the todo task to delete | |
int64 id = 2; | |
} | |
// Contains status of delete operation | |
message DeleteResponse{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
// Contains number of entities have beed deleted | |
// Equals 1 in case of succesfull delete | |
int64 deleted = 2; | |
} | |
// Request data to read all todo task | |
message ReadAllRequest{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
} | |
// Contains list of all todo tasks | |
message ReadAllResponse{ | |
// API versioning: it is my best practice to specify version explicitly | |
string api = 1; | |
// List of all todo tasks | |
repeated ToDo toDos = 2; | |
} | |
// Service to manage list of todo tasks | |
service ToDoService { | |
// Read all todo tasks | |
rpc ReadAll(ReadAllRequest) returns (ReadAllResponse){ | |
option (google.api.http) = { | |
get: "/v1/todo/all" | |
}; | |
} | |
// Create new todo task | |
rpc Create(CreateRequest) returns (CreateResponse){ | |
option (google.api.http) = { | |
post: "/v1/todo" | |
body: "*" | |
}; | |
} | |
// Read todo task | |
rpc Read(ReadRequest) returns (ReadResponse){ | |
option (google.api.http) = { | |
get: "/v1/todo/{id}" | |
}; | |
} | |
// Update todo task | |
rpc Update(UpdateRequest) returns (UpdateResponse){ | |
option (google.api.http) = { | |
put: "/v1/todo/{toDo.id}" | |
body: "*" | |
additional_bindings { | |
patch: "/v1/todo/{toDo.id}" | |
body: "*" | |
} | |
}; | |
} | |
// Delete todo task | |
rpc Delete(DeleteRequest) returns (DeleteResponse){ | |
option (google.api.http) = { | |
delete: "/v1/todo/{id}" | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment