Einar  Hintz

Einar Hintz

1599353646

10 Steps to Replace REST Services with gRPC-Web in Blazor WebAssembly

In modern web applications, the common way data is exchanged between client and server is through REST (representational state transfer) servicesJSON is the standard file format for this two-way communication.

In REST, the client makes a request to a specific endpoint, and the server responds to it.

This architectural style works fine and has been the standard for several years. All web frameworks for creating SPA (single-page applications) are based on it. At first glance, even Blazor WebAssembly seems to use REST just like other frameworks.

Despite the wide use of this standard, there are some critical issues to consider:

  • If it is true that JSON is less verbose than XML, then it is also true that it is not optimized for bandwidth. Sometimes, JSON structure gets much too complicated.
  • REST APIs are stateless. This can have some negative consequences; for example, all requests should contain all the necessary information in order to perform the desired operations.
  • REST is not a protocol, but an architectural style. This involves increasing the responsibilities of developers. Most implementations of REST use only a subset of its principles but work, more or less. Often there is a confusion between REST services and RESTful services (those that implement REST services).

To be clear, REST architecture remains a great way to exchange data between clients and servers, but perhaps today we can afford to look beyond to find alternative solutions.

What are gRPC and gRPC-Web?

gRPC is a remote procedure call system created at Google in 2015. It is open source and can be defined as a replacement for Windows Communication Foundation (WCF). However, thanks to the latest update, it can also substitute REST API.

gRPC uses Protobuf (Protocol Buffers) as the format for the payload and supports all kinds of streaming:

  • Server-side streaming
  • Client-side streaming
  • Bidirectional streaming

From a performance point of view, Protobuf is an efficient binary message format. Protobuf serialization results in small message payloads, which is important in limited-bandwidth scenarios like mobile and web apps.

gRPC defines the contract of services and messages by the .proto file shared between the server and client. It allows you to automatically generate client libraries. gRPC is consistent across platforms and implementations.

The following table shows a comparison of features between gRPC and REST APIs with JSON format.

FeaturesgRPCREST APIs with JSONContractRequired (.proto)OptionalProtocolHTTP/2HTTPPayloadProtobuf (small, binary)JSON (large, human readable)PrescriptivenessStrict specificationLoose. Any HTTP is valid.StreamingClient, server, bi-directionalClient, serverSecurityTransport (TLS)Transport (TLS)Client code generationYesOpenAPI + third-party tooling

All of this sounds great, doesn’t it? Unfortunately, there’s bad news!

gRPC can’t be used from within web browsers because it requires HTTP/2 binary protocol. Don’t worry, the solution to this problem is called gRPC-Web, which makes gRPC usable in the browser. There’s also an implementation of gRPC-Web for .NET that has been officially released.

To be fair, gRPC-Web provides limited gRPC support. For example, client and bi-directional streaming aren’t supported, and there is limited support for server streaming too.

After this preamble, it’s time to go from theory to practice!

In this post I’ll show you how to consume a gRPC-Web service from within a Blazor WebAssembly app to build weather forecasting application. At the time of writing, there’s no native project template for this yet, so adding gRPC support to a Blazor WebAssembly app is a somewhat significant task. But again, don’t worry. No part of this is complicated. It’s only 10 small steps!

#blazor #development #web #grpc #productivity #wasm #webassembly

What is GEEK

Buddha Community

10 Steps to Replace REST Services with gRPC-Web in Blazor WebAssembly
Einar  Hintz

Einar Hintz

1599353646

10 Steps to Replace REST Services with gRPC-Web in Blazor WebAssembly

In modern web applications, the common way data is exchanged between client and server is through REST (representational state transfer) servicesJSON is the standard file format for this two-way communication.

In REST, the client makes a request to a specific endpoint, and the server responds to it.

This architectural style works fine and has been the standard for several years. All web frameworks for creating SPA (single-page applications) are based on it. At first glance, even Blazor WebAssembly seems to use REST just like other frameworks.

Despite the wide use of this standard, there are some critical issues to consider:

  • If it is true that JSON is less verbose than XML, then it is also true that it is not optimized for bandwidth. Sometimes, JSON structure gets much too complicated.
  • REST APIs are stateless. This can have some negative consequences; for example, all requests should contain all the necessary information in order to perform the desired operations.
  • REST is not a protocol, but an architectural style. This involves increasing the responsibilities of developers. Most implementations of REST use only a subset of its principles but work, more or less. Often there is a confusion between REST services and RESTful services (those that implement REST services).

To be clear, REST architecture remains a great way to exchange data between clients and servers, but perhaps today we can afford to look beyond to find alternative solutions.

What are gRPC and gRPC-Web?

gRPC is a remote procedure call system created at Google in 2015. It is open source and can be defined as a replacement for Windows Communication Foundation (WCF). However, thanks to the latest update, it can also substitute REST API.

gRPC uses Protobuf (Protocol Buffers) as the format for the payload and supports all kinds of streaming:

  • Server-side streaming
  • Client-side streaming
  • Bidirectional streaming

From a performance point of view, Protobuf is an efficient binary message format. Protobuf serialization results in small message payloads, which is important in limited-bandwidth scenarios like mobile and web apps.

gRPC defines the contract of services and messages by the .proto file shared between the server and client. It allows you to automatically generate client libraries. gRPC is consistent across platforms and implementations.

The following table shows a comparison of features between gRPC and REST APIs with JSON format.

FeaturesgRPCREST APIs with JSONContractRequired (.proto)OptionalProtocolHTTP/2HTTPPayloadProtobuf (small, binary)JSON (large, human readable)PrescriptivenessStrict specificationLoose. Any HTTP is valid.StreamingClient, server, bi-directionalClient, serverSecurityTransport (TLS)Transport (TLS)Client code generationYesOpenAPI + third-party tooling

All of this sounds great, doesn’t it? Unfortunately, there’s bad news!

gRPC can’t be used from within web browsers because it requires HTTP/2 binary protocol. Don’t worry, the solution to this problem is called gRPC-Web, which makes gRPC usable in the browser. There’s also an implementation of gRPC-Web for .NET that has been officially released.

To be fair, gRPC-Web provides limited gRPC support. For example, client and bi-directional streaming aren’t supported, and there is limited support for server streaming too.

After this preamble, it’s time to go from theory to practice!

In this post I’ll show you how to consume a gRPC-Web service from within a Blazor WebAssembly app to build weather forecasting application. At the time of writing, there’s no native project template for this yet, so adding gRPC support to a Blazor WebAssembly app is a somewhat significant task. But again, don’t worry. No part of this is complicated. It’s only 10 small steps!

#blazor #development #web #grpc #productivity #wasm #webassembly

Jamal  Lemke

Jamal Lemke

1600056000

Blazor for ASP.NET Web Forms Developers PDF

Blazor is a new web framework that changes what is possible when building web apps with .NET. It is also a client-side web UI framework based on C## instead of JavaScript. When paired with .NET running on the server, Blazor enables full-stack web development with .NET.

It also builds on the foundations of .NET Core to provide a modern and high-performance web development experience. Additionally, Blazor is a natural solution for ASP.NET Web Forms developers looking to take advantage of client-side development and the open-source, cross-platform future of .NET.

This e-book pdf covers the following ASP.NET Web Forms features and practices:-

  • Building Blazor apps.
  • How Blazor works.
  • Blazor’s relation to .NET Core.
  • Reasonable strategies for migrating existing ASP.NET Web Forms apps to Blazor where appropriate.
  • A reference sample that demonstrates the migration strategies used.

#articles #asp.net #blazor #blazor for asp.net web forms #blazor for asp.net web forms developers #blazor web forms #convert web forms to blazor

Blazor : Calling REST API ASP NET Core Blazor | WEB API

#blazor #blazor tutorial #blazor curd #blazor in c# #blazor webassembly

Salis  Ajingi

Salis Ajingi

1619846700

REST API & RESTful Web Services Explained | Web Services Tutorial

In this tutorial we will learn REST API and RESTful web services.

What is REST API? REST stands for Representational State Transfer and API stands for Application Programming Interface.

Representational - the resource (image, page, video, profile) is represented by the web server to the client in any format like HTML, Image, JSON, XML etc.

State - the state of the application (web site) on a client’s computer changes as the client clicks from one link to the next. Ask the client clicks on the link, they request additional resources, and the application “state” changes.

Transfer - the transfer of resources from the web server to the client in a “representational” state which can be read by the client or implemented in the application program by the programmer. The transfer may also refer to the application state transfer as the client browses a web site.

API - application programming interface provides useful methods/functions which a programmer can implement into his own application in a chosen programming language like PHP. The API makes it easy for programmers to implement. It’s important to note that the response we get when sending REST API request will usually be in JSON, XML or other format which makes it easy to implement in the code and it’s not meant to be read immediately by a human being.

Download this video’s files here:

https://www.patreon.com/posts/rest-ap…

Subscribe: https://www.youtube.com/c/CleverTechieTube/featured

#rest #restful #web-service

Rahim Makhani

Rahim Makhani

1621483980

Get the best web app for your Business FUTURE

The web app is application software that runs on the webserver. You can easily use the web app by searching it in the web browser through Google or any other search engine, or you can also add shortcuts of the web app to your smartphone.

Web app for your business helps you to reach new customers and enables them to know about your firm and the services you provide and can know about your organization’s feedback and rating. It can also help you with the advertisement of your app among all.

Do you want to develop a web app for your business? Then it would help if you collaborated with Nevina Infotech, which is the best web application development company that will help you develop a unique web app with the help of its dedicated developers.

#web application development company #web application development services #web app development company #custom web application development company #web app development services #custom web application development services