Introduce restconf.server.api.HttpGetResource
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / api / RestconfServer.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.server.api;
9
10 import java.net.URI;
11 import org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.restconf.api.ApiPath;
14 import org.opendaylight.restconf.api.FormattableBody;
15 import org.opendaylight.restconf.api.QueryParameters;
16 import org.opendaylight.restconf.common.errors.RestconfFuture;
17 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
18 import org.opendaylight.yangtools.yang.common.Empty;
19
20 /**
21  * An implementation of a RESTCONF server, implementing the
22  * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.3">RESTCONF API Resource</a>.
23  */
24 @NonNullByDefault
25 public interface RestconfServer {
26     /**
27      * Delete a data resource.
28      *
29      * @param identifier resource identifier
30      * @return A {@link RestconfFuture} of the operation
31      */
32     @SuppressWarnings("checkstyle:abbreviationAsWordInName")
33     RestconfFuture<Empty> dataDELETE(ApiPath identifier);
34
35     /**
36      * Return the content of the datastore.
37      *
38      * @param params {@link DataGetParams} for this request
39      * @return A {@link RestconfFuture} of the {@link DataGetResult} content
40      */
41     RestconfFuture<DataGetResult> dataGET(QueryParameters params);
42
43     /**
44      * Return the content of a data resource.
45      *
46      * @param identifier resource identifier
47      * @param params {@link DataGetParams} for this request
48      * @return A {@link RestconfFuture} of the {@link DataGetResult} content
49      */
50     RestconfFuture<DataGetResult> dataGET(ApiPath identifier, QueryParameters params);
51
52     /**
53      * Partially modify the target data resource, as defined in
54      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.6.1">RFC8040, section 4.6.1</a>.
55      *
56      * @param body data node for put to config DS
57      * @return A {@link RestconfFuture} of the operation
58      */
59     RestconfFuture<DataPatchResult> dataPATCH(ResourceBody body);
60
61     /**
62      * Partially modify the target data resource, as defined in
63      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.6.1">RFC8040, section 4.6.1</a>.
64      *
65      * @param identifier resource identifier
66      * @param body data node for put to config DS
67      * @return A {@link RestconfFuture} of the operation
68      */
69     RestconfFuture<DataPatchResult> dataPATCH(ApiPath identifier, ResourceBody body);
70
71     /**
72      * Ordered list of edits that are applied to the datastore by the server, as defined in
73      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
74      *
75      * @param params query parameters
76      * @param body YANG Patch body
77      * @return A {@link RestconfFuture} of the {@link DataYangPatchResult} content
78      */
79     RestconfFuture<DataYangPatchResult> dataPATCH(QueryParameters params, PatchBody body);
80
81     /**
82      * Ordered list of edits that are applied to the datastore by the server, as defined in
83      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
84      *
85      * @param identifier path to target
86      * @param params query parameters
87      * @param body YANG Patch body
88      * @return A {@link RestconfFuture} of the {@link DataYangPatchResult} content
89      */
90     RestconfFuture<DataYangPatchResult> dataPATCH(ApiPath identifier, QueryParameters params, PatchBody body);
91
92     RestconfFuture<CreateResourceResult> dataPOST(QueryParameters params, ChildBody body);
93
94     /**
95      * Create or invoke a operation, as described in
96      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.4">RFC8040 section 4.4</a>.
97      *
98      * @param identifier path to target
99      * @param params query parameters
100      * @param body body of the post request
101      */
102     RestconfFuture<? extends DataPostResult> dataPOST(ApiPath identifier, QueryParameters params, DataPostBody body);
103
104     /**
105      * Replace the data store, as described in
106      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.5">RFC8040 section 4.5</a>.
107      *
108      * @param body data node for put to config DS
109      * @param params query parameters
110      * @return A {@link RestconfFuture} completing with {@link DataPutResult}
111      */
112     RestconfFuture<DataPutResult> dataPUT(QueryParameters params, ResourceBody body);
113
114     /**
115      * Create or replace a data store resource, as described in
116      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.5">RFC8040 section 4.5</a>.
117      *
118      * @param identifier resource identifier
119      * @param params query parameters
120      * @param body data node for put to config DS
121      * @return A {@link RestconfFuture} completing with {@link DataPutResult}
122      */
123     RestconfFuture<DataPutResult> dataPUT(ApiPath identifier, QueryParameters params, ResourceBody body);
124
125     /**
126      * Return the set of supported RPCs supported by
127      *  {@link #operationsPOST(URI, ApiPath, QueryParameters, OperationInputBody)},
128      * as expressed in the <a href="https://www.rfc-editor.org/rfc/rfc8040#page-84">ietf-restconf.yang</a>
129      * {@code container operations} statement.
130      *
131      * @return A {@link RestconfFuture} completing with an {@link FormattableBody}
132      */
133     RestconfFuture<FormattableBody> operationsGET();
134
135     /*
136      * Return the details about a particular operation supported by
137      * {@link #operationsPOST(URI, String, OperationInputBody)}, as expressed in the
138      * <a href="https://www.rfc-editor.org/rfc/rfc8040#page-84">ietf-restconfig.yang</a>
139      * {@code container operations} statement.
140      *
141      * @param operation An operation
142      * @return A {@link RestconfFuture} completing with an {@link FormattableBody}
143      */
144     RestconfFuture<FormattableBody> operationsGET(ApiPath operation);
145
146     /**
147      * Invoke an RPC operation, as defined in
148      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.6">RFC8040 Operation Resource</a>.
149      *
150      * @param restconfURI Base URI of the request
151      * @param operation {@code <operation>} path, really an {@link ApiPath} to an {@code rpc}
152      * @param params query parameters
153      * @param body RPC operation
154      * @return A {@link RestconfFuture} completing with {@link InvokeResult}
155      */
156     // FIXME: 'operation' should really be an ApiIdentifier with non-null module, but we also support yang-ext:mount,
157     //        and hence it is a path right now
158     RestconfFuture<InvokeResult> operationsPOST(URI restconfURI, ApiPath operation, QueryParameters params,
159         OperationInputBody body);
160
161     /**
162      * Return the revision of {@code ietf-yang-library} module implemented by this server, as defined in
163      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.3.3">RFC8040 {+restconf}/yang-library-version</a>.
164      *
165      * @return A {@link RestconfFuture} completing with {@link NormalizedNodePayload} containing a single
166      *        {@code yang-library-version} leaf element.
167      */
168     // FIXME: this is a simple encoding-variadic return, similar to how OperationsContent is handled use a common
169     //        construct for both cases -- in this case it carries a yang.common.Revision
170     RestconfFuture<FormattableBody> yangLibraryVersionGET();
171
172     RestconfFuture<ModulesGetResult> modulesYangGET(String fileName, @Nullable String revision);
173
174     RestconfFuture<ModulesGetResult> modulesYangGET(ApiPath mountPath, String fileName, @Nullable String revision);
175
176     RestconfFuture<ModulesGetResult> modulesYinGET(String fileName, @Nullable String revision);
177
178     RestconfFuture<ModulesGetResult> modulesYinGET(ApiPath mountPath, String fileName, @Nullable String revision);
179 }