Code Monkey home page Code Monkey logo

grpc-crud-demo's Introduction

CRUD service implemented in gRPC

This is a simple demo of implementing a bookstore service using gRPC framework - see below protobuf file.

How to run the demo

You can run the server by running the following commands:

go run main.go // this will fire up the server

go run client/client.go // this will fire up the client

Service API definition

The api definition is defined in proto file - see below

syntax = "proto3";

package api;

import "google/protobuf/empty.proto";

// A simple Bookstore API.
//
// The API manages shelves and books resources. Shelves contain books.
service Bookstore {
    // Returns a list of all shelves in the bookstore.
    rpc ListShelves(google.protobuf.Empty) returns (ListShelvesResponse) {}
    // Creates a new shelf in the bookstore.
    rpc CreateShelf(CreateShelfRequest) returns (Shelf) {}
    // Returns a specific bookstore shelf.
    rpc GetShelf(GetShelfRequest) returns (Shelf) {}
    // Deletes a shelf, including all books that are stored on the shelf.
    rpc DeleteShelf(DeleteShelfRequest) returns (google.protobuf.Empty) {}
    // Returns a list of books on a shelf.
    rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) {}
    // Creates a new book.
    rpc CreateBook(CreateBookRequest) returns (Book) {}
    // Returns a specific book.
    rpc GetBook(GetBookRequest) returns (Book) {}
    // Deletes a book from a shelf.
    rpc DeleteBook(DeleteBookRequest) returns (google.protobuf.Empty) {}
}

// A shelf resource.
message Shelf {
    // A unique shelf id.
    int64 id = 1;
    // A theme of the shelf (fiction, poetry, etc).
    string theme = 2;
}

// A book resource.
message Book {
    // A unique book id.
    int64 id = 1;
    // An author of the book.
    string author = 2;
    // A book title.
    string title = 3;
}

// Response to ListShelves call.
message ListShelvesResponse {
    // Shelves in the bookstore.
    repeated Shelf shelves = 1;
}

// Request message for CreateShelf method.
message CreateShelfRequest {
    // The shelf resource to create.
    Shelf shelf = 1;
}

// Request message for GetShelf method.
message GetShelfRequest {
    // The ID of the shelf resource to retrieve.
    int64 shelf = 1;
}

// Request message for DeleteShelf method.
message DeleteShelfRequest {
    // The ID of the shelf to delete.
    int64 shelf = 1;
}

// Request message for ListBooks method.
message ListBooksRequest {
    // ID of the shelf which books to list.
    int64 shelf = 1;
}

// Response message to ListBooks method.
message ListBooksResponse {
    // The books on the shelf.
    repeated Book books = 1;
}

// Request message for CreateBook method.
message CreateBookRequest {
    // The ID of the shelf on which to create a book.
    int64 shelf = 1;
    // A book resource to create on the shelf.
    Book book = 2;
}

// Request message for GetBook method.
message GetBookRequest {
    // The ID of the shelf from which to retrieve a book.
    int64 shelf = 1;
    // The ID of the book to retrieve.
    int64 book = 2;
}

// Request message for DeleteBook method.
message DeleteBookRequest {
    // The ID of the shelf from which to delete a book.
    int64 shelf = 1;
    // The ID of the book to delete.
    int64 book = 2;
}

grpc-crud-demo's People

Contributors

akhettar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.