Junior
// task 2 // 1. OpenAPI + gRPC // (YAML) // info: // title: Book API // version: .. // paths: // /books: // get: // responses: // "200"
sobes.tech AI
Answer from AI
OpenAPI is a specification for describing REST APIs, usually in YAML or JSON format. It describes paths (endpoints), HTTP methods, parameters, responses, etc.
gRPC is a framework for remote procedure calls (RPC), using Protocol Buffers for data serialization and HTTP/2 for transport.
Example of using OpenAPI to describe a REST API:
openapi: 3.0.0
info:
title: Book API
version: 1.0.0
paths:
/books:
get:
summary: Get list of books
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
type: object
properties:
id:
type: integer
title:
type: string
For gRPC, a .proto file is used, for example:
syntax = "proto3";
service BookService {
rpc GetBooks (Empty) returns (BooksResponse);
}
message Empty {}
message Book {
int32 id = 1;
string title = 2;
}
message BooksResponse {
repeated Book books = 1;
}
Thus, OpenAPI and gRPC are different approaches to describing and implementing APIs: REST with OpenAPI and RPC with gRPC.