The commands are shown below for your convenience:Įnter fullscreen mode Exit fullscreen mode Follow the README instructions to install dependencies and build the apiTypes package. Clone the anthonydmays/grpc-vs-rest repo to your machine, open a terminal, and change into the rest-api-app directory. These demos are not designed to show you how to write production-ready systems, but rather to help you understand each style sufficiently.įirst, let's get the API and client up and running. In order to highlight the differences when moving between styles, I've done my best to minimize differences between the sample projects at the expense of some best practices. It should be fairly trivial to write unit tests for our API to ensure that we have the behavior we expect. We want to allow any clients to use our API from the browser environment. We should be able to ensure that our entire codebase is type-safe and supports modern IDE niceties like autocomplete. We just want to be able to list all of our contacts and create, update, or delete a single contact. Nothing special here in the way of functional requirements. To keep things simple, I only have a few features I've implemented along with several key constraints. You can find the sample project monorepos on GitHub at anthonydmays/grpc-vs-rest. All of the projects we'll examine are implemented as a full-stack address book apps with a simple front-end UI built on Svelte and a NodeJS back-end API. Let's take a look at some sample projects that demonstrate the distinctions between the REST and gRPC architectural styles. For gRPC, Google chose to develop its own format called "Protocol Buffers" (or "protobufs" for short) which benefit from a very efficient wire serialization format designed for speed.ĭemonstrating an address book using REST and gRPC Tools are required to generate server and client stub classes from the interface definition that can be used in a variety of programming languages. Unlike RESTful APIs, RPC-based APIs define procedures (or methods) using an Interface Definition Language (IDL). Performance is the killer feature of gRPC. This makes it very efficient for building high-performance, high-throughput applications. Built to leverage the newer HTTP/2 protocol under the hood, gRPC supports bidirectional communication between clients and servers in addition to streaming capabilities that enable multiple messages per request or response. However, Google's implementation known as gRPC was invented in 2015 as a performance-centric framework for enabling web communication between systems. The distributed client-server communication style known as "Remote Procedure Call" (RPC) is nothing new, dating back to at least the early 80s. To that end, no special software is required in order to build or use RESTful APIs. REST is designed to leverage all of the existing technologies that make the web work, especially HTTP, TCP, URLs, and hypermedia types like JSON, XML, and HTML. ![]() Users only need to visit a single URL and links provided on the resulting page inform the user where they can browse. ![]() This is similar to how users interact with web pages today. ![]() Simply put, instead of clients choosing what methods to invoke to change an application's state, it's the hypermedia itself that determines what resources a client can interact with and at what time. ![]() Typically, clients use HTTP as the protocol of choice for building and interacting with RESTful service.Īn oft neglected but critical concept to REST is the idea of hypermedia as the engine of application state (HATEOAS). Modifying these resources changes the application state. A RESTful API allows users to interact with resources identified by URLs and encoded in a variety of hypermedia representations (such as JSON, XML, or HTML). The goal was to leverage decades of wisdom around building distributed systems that helped to ensure good separation of concerns and scalability.Ĭentral to the REST philosophy is the concept of hypermedia and hypertext (like the "H" in HTTP). He outlined several constraints for system architecture rooted in the principles that drive the web itself. In 2000, Roy Fielding wrote his dissertation and introduced the world to an architecture for distributed systems called "Representational State Transfer," or REST for short. Our goal is to understand how to use these architectural styles to build APIs. In this article, we'll explore APIs created using both the REST architecture and a fairly new player called gRPC.
0 Comments
Leave a Reply. |