如何在Opendaylight中操作YANG生成的REST API GET?

问题描述 投票:0回答:1

PUT,DELETE,POST可以如下操作。

顺便说一句,我不知道怎么做GET。

请帮我。

// PUT & DELETE (mapped to WRITE, DELETE of MD-SAL)
public void onDataTreeChanged(Collection<DataTreeModification<GreetingRegistry>> changes) {
  for(DataTreeModification<GreetingRegistry> change: changes) {
     DataObjectModification<GreetingRegistry> rootNode = change.getRootNode();
     if(rootNode.getModificationType() == WRITE) {
        ...
     }
     else if(rootNode.getModificationType() == DELETE) {
        ...
     }
}


// POST (mapped to RPC of MD-SAL)
public Future<RpcResult<HelloWorldOutput>> helloWorld(HelloWorldInput input) 
{
  HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();
  helloBuilder.setGreeting("Hello " + input.getName());
  return RpcResultBuilder.success(helloBuilder.build()).buildFuture();
}

// GET (???)
How should I implement it?
opendaylight
1个回答
0
投票

实际上,您不必在代码中为GET实现任何内容,当您想要从YANG建模的MD-SAL数据中读取时,默认情况下GET方法可用,并返回您在URL中要求的任何数据。指向正确的URL非常重要。

如果要在将数据返回给用户之前对数据进行一些处理,可以将RPC与POST一起使用,并在基于RPC的方法中进行处理。在上面的示例中,您可以将搜索键放入HelloWorldInput,在helloWorld()中进行处理,并在HelloWorldOutput中返回结果。

© www.soinside.com 2019 - 2024. All rights reserved.