0.0.18 • Published 14 days ago

webpb v0.0.18

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
14 days ago

webpb

Generate api definitions for web framework from protocol buffers file

Cli tool

Options

  • usage
java -jar webpb.jar
Missing required options [--type=<type>, --out=<out>, --proto_path=<protoPaths>]
Usage: webpb [-hV] --out=<out> [--quiet=<quiet>] --type=<type>
             [--excludes=<excludes>...]... [--files=<files>...]...
             [--includes=<includes>...]... --proto_path=<protoPaths>...
             [--proto_path=<protoPaths>...]...
      --excludes=<excludes>...
                           Excluded paths.
      --files=<files>...   Source files.
  -h, --help               Show this help message and exit.
      --includes=<includes>...
                           Included paths.
      --out=<out>          Generated code output directory.
      --proto_path=<protoPaths>...
                           Paths to resolving proto files.
      --quiet=<quiet>      Hide logs.
      --type=<type>        TS, JAVA.
  -V, --version            Print version information and exit.
  • example

java -jar webpb.jar --type=JAVA --proto_path=example/proto --out=/tmp/protocol

Integration

Definition

message StoresRequest {
    option (method) = "POST";

    option (path) = "/stores/{type}?page={paging.page}&size={paging.size}";

    required ResourceProto.PageablePb pageable = 1 [(omitted) = true];
    required int32 type = 2 [(omitted) = true];
    required int32 city = 3 [(java_anno) = '@NotNull(message = "City is required")', (java_anno) = '@Range(min = 0)'];
}

Web

NPM package

https://www.npmjs.com/package/webpb

Sample request

  • Generated typescript code
export interface IStoresRequest {
    pageable: ResourceProto.IPageablePb;
    type: number;
    city: number;
}

export class StoresRequest implements IStoresRequest, Webpb.WebpbMessage {
    pageable!: ResourceProto.IPageablePb;
    type!: number;
    city!: number;
    META: () => Webpb.WebpbMeta;

    private constructor(p: IStoresRequest) {
        Webpb.assign(p, this, ["pageable", "type"]);
        this.META = () => ({
            class: 'StoresRequest',
            method: 'POST',
            path: `/stores/${p.type}${Webpb.query({
                page: Webpb.getter(p, 'pageable.page'),
                size: Webpb.getter(p, 'pageable.size'),
            })}`
        });
    }

    static create(properties: IStoresRequest): StoresRequest {
        return new StoresRequest(properties);
    }
}
  • Request with some http client, given feignClient
const message = StoresRequest.create({
    pageable: {
        page: 1,
        size: 10
    },
    city: 100,
    type: 1
});

let meta = message.META();
feignClient.request({
    method: meta.method,
    url: meta.path,
    body: message
})

Spring boot

Maven package

https://mvnrepository.com/artifact/com.github.jg513/webpb-spring

Sample request mapping

  • Generated java code
@Setter
@Getter
@Accessors(chain = true)
public class StoresRequest implements WebpbMessage {

    public static final String METHOD = "POST";

    public static final String PATH = "/stores/{type}";

    @NotNull(message = "City is required")
    @Range(min = 0)
    private Integer city;
}
  • Register bean
@Bean
@Order(0)
public WebMvcRegistrations webMvcRegistrationsHandlerMapping() {
    return new WebMvcRegistrations() {
        @Override
        public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
            return new WebpbRequestControllerMapping();
        }
    };
}
  • Controller
@WebpbMapping
public void findAll(Pageable pageable, @Valid @RequestBody StoresRequest request) {
    return storeService.findAll(pageable, request);
}
0.0.18

14 days ago

0.0.17

4 months ago

0.0.16

10 months ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago