Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implemented jsonplaceholders rest apis grpc method #50

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
use std::path::PathBuf;

fn main() {
fn configure_tonic() -> tonic_build::Builder {
tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.build_server(true)
.build_client(true)
}

// Compile news.proto
let mut news = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
news.push("news.proto");
tonic_build::compile_protos(news).expect("Failed to compile protos");

// Configure and compile each proto file with descriptors
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());

tonic_build::configure()
// Compile news.proto
configure_tonic()
.file_descriptor_set_path(out_dir.join("news_descriptor.bin"))
.compile(&["news.proto"], &["proto"])
.unwrap();
.compile(&["news.proto"], &["."])
.expect("Failed to compile news.proto");

// Compile posts.proto
configure_tonic()
.file_descriptor_set_path(out_dir.join("posts_descriptor.bin"))
.compile(&["posts.proto"], &["."])
.expect("Failed to compile posts.proto");

// Compile users.proto
configure_tonic()
.file_descriptor_set_path(out_dir.join("users_descriptor.bin"))
.compile(&["users.proto"], &["."])
.expect("Failed to compile users.proto");
}
35 changes: 35 additions & 0 deletions posts.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
syntax = "proto3";
package posts;

message Post {
int32 id = 1;
int32 userId = 2;
string title = 3;
string body = 4;
}

message Filter {
optional int32 userId = 1;
}

message PostRequest {
int32 id = 1;
}

message PostList {
repeated Post posts = 1;
}

message PostResponse {
Post post = 1;
}

message DeleteResponse {}

service PostService {
rpc ListPosts(Filter) returns (PostList);
rpc GetPost(PostRequest) returns (Post);
rpc CreatePost(Post) returns (PostResponse);
rpc UpdatePost(Post) returns (PostResponse);
rpc DeletePost(PostRequest) returns (DeleteResponse);
}
Loading