Skip to content

Instantly share code, notes, and snippets.

@elonsalfati
Last active July 7, 2019 09:11
Show Gist options
  • Save elonsalfati/d81272c850e6ff6fd4730a3d4bbb9f6e to your computer and use it in GitHub Desktop.
Save elonsalfati/d81272c850e6ff6fd4730a3d4bbb9f6e to your computer and use it in GitHub Desktop.
medium-tutorial-events-manager-proto
// Set the syntax to proto3
syntax = "proto3";
// Set the generated files to be under package v1
package v1;
// import definitions from protobuf
import "google/protobuf/timestamp.proto";
// import swagger generator
import "google/api/annotations.proto";
import "protoc-gen-swagger/options/annotations.proto";
// Define the options for the swagger file - REST Gateway
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
info: {
title: "Events Manager";
version: "1.0";
contact: {
name: "Events Manager Service";
url: "https://github.com/ElonSalfati/events-manager";
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;
}
}
}
}
};
// Define the Events format
message Event {
// The id for the event
string id = 1;
// Define the avaliable events
enum EventType {
UNIVERSAL = 0;
WEB = 1;
IMAGES = 2;
LOCAL = 3;
NEWS = 4;
PRODUCTS = 5;
VIDEO = 6;
}
// Describe the event type
EventType eventType = 2;
// The title of the event
string title = 3;
// Description of what happend during the event
string description = 4;
// Timestamp
google.protobuf.Timestamp reminder = 5;
}
// -------------------------------------------------------------- //
// Define the request and the response format for the each event //
// -------------------------------------------------------------- //
// Define the create event for the request
message CreateEventRequest{
// Api version
string api = 1;
// The event that should be created
Event event = 2;
}
// Define the create event for the response
message CreateEventResponse{
// Api version
string api = 1;
// The id of the event that has been created
string id = 2;
}
// Define the read event for the request
message ReadEventRequest{
// Api version
string api = 1;
// The id of the desired event - if all return all events
string id = 2;
}
// Define the read event for the response
message ReadEventResponse{
// Api version
string api = 1;
// The event(s)
repeated Event events = 2;
}
// Define the update event for the request
message UpdateEventRequest{
// Api version
string api = 1;
// The entity to update
Event event = 2;
}
// Define the update event for the response
message UpdateEventResponse{
// Api version
string api = 1;
// The status of the process
bool updated = 2;
}
// Define the delete event for the request
message DeleteEventRequest{
// Api version
string api = 1;
// The id of the event that will be deleted
string id = 2;
}
// Define the delete event for the response
message DeleteEventResponse{
// Api version
string api = 1;
// The status of the process
bool deleted = 2;
}
// ----------------------------- //
// Define the service endpoints //
// ----------------------------- //
// Service that manages events
service EventsManagerService {
// Create new events
rpc CreateEvent(CreateEventRequest) returns (CreateEventResponse) {
// Define the REST endpoint
option (google.api.http) = {
post: "/api/v1/event"
body: "*"
};
}
// Read event(s)
rpc ReadEvent(ReadEventRequest) returns (ReadEventResponse) {
// Define the REST endpoint
option (google.api.http) = {
get: "/api/v1/event/{id}"
};
}
// Update event
rpc UpdateEvent(UpdateEventRequest) returns (UpdateEventResponse) {
// Define the REST endpoint
option (google.api.http) = {
patch: "/api/v1/event/{event.id}"
body: "*"
};
}
// Delete event
rpc DeleteEvent(DeleteEventRequest) returns (DeleteEventResponse) {
// Define the REST endpoint
option (google.api.http) = {
delete: "/api/v1/event/{id}"
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment