简体   繁体   中英

What is the difference between registerWebInterface and registerRestInterface and RestInterfaceClient?

I can't understand by docs what is the difference between registerRestInterface , registerWebInterface and RestInterfaceClient .

Both of them can generate methods by class. But I can't understand when I should use one and when another.

The key to understand the difference is to realize that vibe.web.rest and vibe.web.web are two different modules with a different use cases in mind:

vibe.web.rest

  • meant for stateless communication
  • requires to define an abstract interface
  • RestInterfaceClient can be used to communicate with other Rest interfaces
  • A JS client can be generated from the API interfaces
  • can be registered with registerRestInterface

When to use:

  • large public APIs
  • API needs to be shared with others

-> usage example

vibe.web.web

  • intended for web services
  • allows direct access to the current session and request context
  • provides many convenience functions based on the request (eg redirect )
  • allows @auth ( example )
  • can be registered with registerWebInterface

When to use: web services, small APIs

-> usage example

I personally use vibe.web.web more often as for my small projects the overhead of keeping the interface files in sync isn't worth it. Moreover, I like the convenient access to the request context and session variables in vibe.web.web . In fact, I maintain a drop-in fork that adds more convenience feature (auto-serialization to/from Json, auto route /:param/ generation based on the method params, ...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM