Skip to content

Releases: webrpc/webrpc

v0.11.2

10 Jul 18:38
94335ea
Compare
Choose a tag to compare

Changelog

Docker

docker pull ghcr.io/webrpc/webrpc-gen:v0.11.2

Example: docker run -v $PWD:$PWD ghcr.io/webrpc/webrpc-gen:v0.11.2 -schema=$PWD/api.ridl -target=golang

Homebrew

brew tap webrpc/tap
brew install webrpc-gen

Build from source

go install -ldflags="-s -w -X github.com/webrpc/webrpc.VERSION=v0.11.2" github.com/webrpc/webrpc/cmd/webrpc-gen@v0.11.2

Download binaries

macOS: amd64, arm64 (Apple Silicon)
Linux: amd64, arm64
Windows: amd64, arm64

v0.11.1

06 Jun 14:05
3d8704f
Compare
Choose a tag to compare

Changelog

Docker

docker pull ghcr.io/webrpc/webrpc-gen:v0.11.1

Example: docker run -v $PWD:$PWD ghcr.io/webrpc/webrpc-gen:v0.11.1 -schema=$PWD/api.ridl -target=golang

Homebrew

brew tap webrpc/tap
brew install webrpc-gen

Build from source

go install -ldflags="-s -w -X github.com/webrpc/webrpc.VERSION=v0.11.1" github.com/webrpc/webrpc/cmd/webrpc-gen@v0.11.1

Download binaries

macOS: amd64, arm64 (Apple Silicon)
Linux: amd64, arm64
Windows: amd64, arm64

v0.11.0 schema errors

23 Mar 10:34
bf6dd73
Compare
Choose a tag to compare

Feature: Define webrpc schema errors

You can now define your own custom schema errors in RIDL file, for example:

error   1 Unauthorized    "unauthorized"        HTTP 401
error   2 ExpiredToken    "expired token"       HTTP 401
error   3 InvalidToken    "invalid token"       HTTP 401
error   4 Deactivated     "account deactivated" HTTP 403
error   5 ConfirmAccount  "confirm your email"  HTTP 403
error   6 AccessDenied    "access denied"       HTTP 403
error   7 MissingArgument "missing argument"    HTTP 400
error   8 UnexpectedValue "unexpected value"    HTTP 400
error 100 RateLimited     "too many requests"   HTTP 429
error 101 DatabaseDown    "service outage"      HTTP 503
error 102 ElasticDown     "search is degraded"  HTTP 503
error 103 NotImplemented  "not implemented"     HTTP 501
error 200 UserNotFound    "user not found"
error 201 UserBusy        "user busy"
error 202 InvalidUsername "invalid username"
error 300 FileTooBig      "file is too big (max 1GB)"
error 301 FileInfected    "file is infected"
error 302 FileType        "unsupported file type"

Note: Unless specified, the default HTTP status for webrpc errors is HTTP 400.

typescript@v0.11.0 breaking changes

  • All errors thrown by webrpc client are now instance of WebrpcError, which extends JavaScript Error. No need to re-throw errors anymore.
  • error.msg error.message
  • by default, the error messages are "human-friendly", they don't contain any details about the backend error cause
  • underlying backend error (for developers) is optionally available as error.cause?
  • error.code or error.message can be used as input for user-friendly error i18n translations

You can now check for explicit error class instance (as defined in RIDL schema) or against a generic WebrpcError class.

try {
  const resp = await testApiClient.getUser();
  // setUser(resp.user)
} catch (error) {
  if (error instanceof RateLimitedError) {
    // retry with back-off time
  }
  
  if (error instanceof UnauthorizedError) {
    // render sign-in page
  }
  
  if (error instanceof WebrpcError) {
    console.log(error.status) // print response HTTP status code (ie. 4xx or 5xx)
    console.log(error.code) // print unique schema error code; generic endpoint errors are 0
    console.log(error.message) // print error message
    console.log(error.cause) // print the underlying backend error -- ie. "DB error" - useful for debugging / reporting to Sentry
  }
  
  // setError(error.message)
}

golang@v0.11.0 breaking changes

Note: You can turn on -legacyErrors=true flag on golang generator (ie. webrpc-gen -target=golang -legacyErrors=true -pkg=proto) in order to preserve the deprecated functions and sentinel errors (see below). This will allow you to migrate your codebase to the new custom schema errors gradually.

The following werbrpc error functions and sentinel errors are now deprecated or removed:

  • proto.WrapError() // Deprecated.
  • proto.Errorf() // Deprecated.
  • proto.HTTPStatusFromErrorCode()
  • proto.IsErrorCode()
  • proto.ErrCanceled // Deprecated.
  • proto.ErrUnknown // Deprecated.
  • proto.ErrFail // Deprecated.
  • proto.ErrInvalidArgument // Deprecated.
  • proto.ErrDeadlineExceeded // Deprecated.
  • proto.ErrNotFound // Deprecated.
  • proto.ErrBadRoute // Deprecated.
  • proto.ErrAlreadyExists // Deprecated.
  • proto.ErrPermissionDenied // Deprecated.
  • proto.ErrUnauthenticated // Deprecated.
  • proto.ErrResourceExhausted // Deprecated.
  • proto.ErrFailedPrecondition // Deprecated.
  • proto.ErrAborted // Deprecated.
  • proto.ErrOutOfRange // Deprecated.
  • proto.ErrUnimplemented // Deprecated.
  • proto.ErrInternal // Deprecated.
  • proto.ErrUnavailable // Deprecated.
  • proto.ErrDataLoss // Deprecated.
  • proto.ErrNone // Deprecated.

The schema errors can now be returned from the RPC endpoints via:

func (s *RPC) RemoveUser(ctx context.Context, userID int64) (bool, error) {
 	r, _ := ctx.Value(proto.HTTPRequestCtxKey).(*http.Request)
 	if s.IsRateLimited(r) {
-		return false, proto.Errorf(proto.ErrUnavailable, "rate limited")
+		return false, proto.ErrRateLimited // HTTP 429 per RIDL schema
 	}
 
 	_, err := s.DB.RemoveUser(ctx, userID)
 	if err != nil {
 		if errors.Is(err, pgx.ErrNoRows) {
-			return false, proto.Errorf(proto.ErrNotFound, "no such user(%v)", userID)
+			return false, proto.ErrUserNotFound
 		}
-		return false, proto.WrapError(proto.ErrInternal, err, "")
+		return false, proto.ErrorWithCause(proto.ErrDatabaseDown, err)
 	}
 
 	return true, nil
}

You can also return any other Go error and webrpc will render generic proto.ErrWebrpcEndpoint error automatically along with HTTP 400 status code.

return fmt.Errorf("some error")

The RPC client(s) can now assert the schema error type by their unique error code:

if err, ok := rpc.RemoveUser(ctx, userID); err != nil {
	if errors.Is(proto.ErrRateLimited) {
		// slow down; retry with back-off strategy
	}
	if errors.Is(proto.ErrUserNotFound) {
		// handle 
	}
	// etc.
}

Changelog

Docker

docker pull ghcr.io/webrpc/webrpc-gen:v0.11.0

Example: docker run -v $PWD:$PWD ghcr.io/webrpc/webrpc-gen:v0.11.0 -schema=$PWD/api.ridl -target=golang

Homebrew

brew tap webrpc/tap
brew install webrpc-gen

Build from source

go install -ldflags="-s -w -X github.com/webrpc/webrpc.VERSION=v0.11.0" github.com/webrpc/webrpc/cmd/webrpc-gen@v0.11.0

Download binaries

macOS: amd64, arm64 (Apple Silicon)
Linux: amd64, arm64
Windows: amd64, arm64

v0.10.0 interoperability tests

30 Dec 17:55
aabb887
Compare
Choose a tag to compare

Tested with the following targets:

Added new interoperability tests

We have defined a new interoperability test suite implementing the following schema:

webrpc = v1

name = Test
version = v0.10.0

service TestApi
  - GetEmpty()
  - GetError()
  
  - GetOne() => (one: Simple)
  - SendOne(one: Simple)

  - GetMulti() => (one: Simple, two: Simple, three: Simple)
  - SendMulti(one: Simple, two: Simple, three: Simple)
  
  - GetComplex() => (complex: Complex)
  - SendComplex(complex: Complex)

All generators are expected to implement TestApi schema and run client/server interoperability tests against a reference webrpc-test binaries).

For more info, see typescript or golang tests.

Breaking changes in ridl package Go API

-func NewParser(r *schema.Reader) *Parser
+func NewParser(fsys fs.FS, path string) *Parser

Breaking changes in gen package Go API

- func NewTemplateSource(proto *schema.WebRPCSchema, target string, config *Config) (*TemplateSource, error)
+ func NewTemplateSource(target string, config *Config) (*TemplateSource, error)

Changelog

Docker

docker pull ghcr.io/webrpc/webrpc-gen:v0.10.0

Example: docker run -v $PWD:$PWD ghcr.io/webrpc/webrpc-gen:v0.10.0 -schema=$PWD/api.ridl -target=golang

Homebrew

brew tap webrpc/tap
brew install webrpc-gen

Build from source

go install -ldflags="-s -w -X github.com/webrpc/webrpc.VERSION=v0.10.0" github.com/webrpc/webrpc/cmd/webrpc-gen@v0.10.0

Download binaries

macOS: amd64, arm64 (Apple Silicon)
Linux: amd64, arm64
Windows: amd64, arm64

v0.9.1

29 Dec 15:04
0339b83
Compare
Choose a tag to compare
  • Allow webrpc-test binary to print out ridl scheme

v0.9.0 RIDL updates

28 Dec 18:30
25708e7
Compare
Choose a tag to compare

Breaking changes in v0.9.0

See https://github.com/webrpc/webrpc/blob/master/CHANGELOG.md#ridl-v090-changes

Migrate to RIDL v0.9.0

TL;DR run find . -name '*.ridl' -exec sed -i -e 's/^message /struct /g' {} \;

See https://github.com/webrpc/webrpc/blob/master/CHANGELOG.md#ridl-v090-migration-guide

Changelog

Docker

docker pull ghcr.io/webrpc/webrpc-gen:v0.9.0

Example: docker run -v $PWD:$PWD ghcr.io/webrpc/webrpc-gen:v0.9.0 -schema=$PWD/api.ridl -target=golang

Homebrew

brew tap webrpc/tap
brew install webrpc-gen

Build from source

go install -ldflags="-s -w -X github.com/webrpc/webrpc.VERSION=v0.9.0" github.com/webrpc/webrpc/cmd/webrpc-gen@v0.9.0

Download binaries

macOS: amd64, arm64 (Apple Silicon)
Linux: amd64, arm64
Windows: amd64, arm64

v0.8.3

21 Dec 17:57
d84328a
Compare
Choose a tag to compare

Changelog

Docker

docker pull ghcr.io/webrpc/webrpc-gen:v0.8.3

Example: docker run -v $PWD:$PWD ghcr.io/webrpc/webrpc-gen:v0.8.3 -schema=$PWD/api.ridl -target=golang

Homebrew

brew tap webrpc/tap
brew install webrpc-gen

Build from source

go install -ldflags="-s -w -X github.com/webrpc/webrpc/gen.VERSION=v0.8.3" github.com/webrpc/webrpc/cmd/webrpc-gen@v0.8.3

Download binaries

macOS: amd64, arm64 (Apple Silicon)
Linux: amd64, arm64
Windows: amd64, arm64

v0.8.2

01 Dec 20:54
Compare
Choose a tag to compare

Changelog

Docker

docker run ghcr.io/webrpc/webrpc-gen:v0.8.2

Homebrew

brew tap webrpc/tap
brew install webrpc-gen

Build from source

go install -ldflags="-s -w -X github.com/webrpc/webrpc/gen.VERSION=v0.8.2" github.com/webrpc/webrpc/cmd/webrpc-gen@v0.8.2

Download binaries

macOS: amd64, arm64 (Apple Silicon)
Linux: amd64, arm64
Windows: amd64, arm64

v0.8.1

30 Nov 12:41
67409a6
Compare
Choose a tag to compare

Changelog

Docker

docker run ghcr.io/webrpc/webrpc-gen:v0.8.1

Homebrew

brew tap webrpc/tap
brew install webrpc-gen

Build from source

go install -ldflags="-s -w -X github.com/webrpc/webrpc/gen.VERSION=v0.8.1" github.com/webrpc/webrpc/cmd/webrpc-gen@v0.8.1

Download binaries

macOS: amd64, arm64 (Apple Silicon)
Linux: amd64, arm64
Windows: amd64, arm64

v0.8.0

25 Nov 14:10
155fd9b
Compare
Choose a tag to compare

Docker

docker run ghcr.io/webrpc/webrpc-gen:v0.8.0

Homebrew

brew install webrpc/tap/webrpc-gen

Build & install from source manually

go install github.com/webrpc/webrpc/cmd/webrpc-gen

Changelog