Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rest-api): Move /rest and /v2 endpoints to /api/v1 #3740

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ iota-rest-api = { path = "crates/iota-rest-api" }
iota-rosetta = { path = "crates/iota-rosetta" }
iota-rpc-loadgen = { path = "crates/iota-rpc-loadgen" }
iota-sdk = { path = "crates/iota-sdk" }
# core-types with json format for REST api
# core-types with json format for REST API
iota-sdk2 = { package = "iota-rust-sdk", git = "ssh://[email protected]/iotaledger/iota-rust-sdk.git", rev = "ed6173d434c77604ddc93aaa1550168fdbe97b09", features = ["hash", "serde", "schemars"] }
iota-simulator = { path = "crates/iota-simulator" }
iota-snapshot = { path = "crates/iota-snapshot" }
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-bridge/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub enum BridgeError {
ZeroValueBridgeTransfer(String),
// Storage Error
Storage(String),
// Rest API Error
// REST API Error
RestAPI(String),
// Uncategorized error
Generic(String),
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-config/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ pub struct NodeConfig {
#[serde(default = "default_json_rpc_address")]
pub json_rpc_address: SocketAddr,

/// Flag to enable the experimental REST API under `/rest`
/// Flag to enable the REST API under `/api/v1`
/// endpoint on the same interface as `json` `rpc` server.
#[serde(default)]
pub enable_experimental_rest_api: bool,
pub enable_rest_api: bool,

/// The address for Prometheus metrics.
#[serde(default = "default_metrics_address")]
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-data-ingestion-core/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl CheckpointReader {
)
.expect("failed to create remote store client");
RemoteStore::Hybrid(object_store, iota_rest_api::Client::new(fn_url))
} else if url.ends_with("/rest") {
} else if url.ends_with("/api/v1") {
RemoteStore::Rest(iota_rest_api::Client::new(url))
} else {
let object_store = create_remote_store_client(
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IOTA Indexer is an off-fullnode service to serve data from the IOTA protocol, in

> [!NOTE]
>
> - Indexer sync workers require the `NodeConfig::enable_experimental_rest_api` flag set to `true` in the node
> - Indexer sync workers require the `NodeConfig::enable_rest_api` flag set to `true` in the node
> - Fullnodes expose read and transaction execution JSON-RPC APIs. Hence, transactions can be executed through fullnodes.
> - Validators expose only read-only JSON-RPC APIs.
> - Indexer instances expose read, write and extended JSON-RPC APIs.
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn main() -> Result<(), IndexerError> {
let mut indexer_config = IndexerConfig::parse();
// TODO: Explore other options as in upstream.
// For the moment we only use the fullnode for fetching checkpoints
indexer_config.remote_store_url = Some(format!("{}/rest", indexer_config.rpc_client_url));
indexer_config.remote_store_url = Some(format!("{}/api/v1", indexer_config.rpc_client_url));
info!("Parsed indexer config: {:#?}", indexer_config);
let (_registry_service, registry) = start_prometheus_server(
// NOTE: this parses the input host addr and port number for socket addr,
Expand Down
8 changes: 4 additions & 4 deletions crates/iota-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl IotaNode {
};

let rest_index = if is_full_node
&& config.enable_experimental_rest_api
&& config.enable_rest_api
&& config.enable_index_processing
{
Some(Arc::new(RestIndexStore::new(
Expand Down Expand Up @@ -1967,7 +1967,7 @@ fn build_kv_store(
)))
}

/// Builds and starts the HTTP server for the Iota node, exposing JSON-RPC and
/// Builds and starts the HTTP server for the IOTA node, exposing JSON-RPC and
/// REST APIs based on the node's configuration.
///
/// This function performs the following tasks:
Expand All @@ -1980,7 +1980,7 @@ fn build_kv_store(
/// TransactionBuilderApi, GovernanceApi, TransactionExecutionApi, and
/// IndexerApi.
/// 4. Optionally, if the REST API is enabled, nests the REST API router under
/// the `/rest` path.
/// the `/api/v1` path.
/// 5. Binds the server to the specified JSON-RPC address and starts listening
/// for incoming connections.
pub async fn build_http_server(
Expand Down Expand Up @@ -2053,7 +2053,7 @@ pub async fn build_http_server(

router = router.merge(json_rpc_router);

if config.enable_experimental_rest_api {
if config.enable_rest_api {
let mut rest_service = iota_rest_api::RestService::new(
Arc::new(RestReadStore::new(state, store)),
software_version,
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-rest-api/openapi/elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Iota Node Api</title>
<title>IOTA Node API</title>
<!-- Embed elements Elements via Web Component -->
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css">
Expand Down
6 changes: 3 additions & 3 deletions crates/iota-rest-api/openapi/openapi.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"openapi": "3.1.0",
"info": {
"title": "Iota Node Api",
"description": "REST Api for interacting with the Iota Blockchain",
"title": "IOTA Node API",
"description": "REST API for interacting with the IOTA Blockchain",
"contact": {
"name": "IOTA Foundation",
"url": "https://github.com/iotaledger/iota"
Expand All @@ -15,7 +15,7 @@
},
"servers": [
{
"url": "/v2"
"url": "/api/v1"
}
],
"paths": {
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-rest-api/src/client/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Client {
)));
}

url.set_path("/v2/");
url.set_path("/api/v1/");

let inner = reqwest::ClientBuilder::new()
.user_agent(USER_AGENT)
Expand Down
17 changes: 4 additions & 13 deletions crates/iota-rest-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,8 @@ impl RestService {
api.register_endpoints(ENDPOINTS.to_owned());

Router::new()
.nest("/v2/", api.to_router().with_state(self.clone()))
.route("/v2", get(|| async { Redirect::permanent("/v2/") }))
// Previously the service used to be hosted at `/rest`. In an effort to migrate folks
// to the new versioned route, we'll issue redirects from `/rest` -> `/v2`.
.route("/rest/*path", axum::routing::method_routing::any(redirect))
.route("/rest", get(|| async { Redirect::permanent("/v2/") }))
.route("/rest/", get(|| async { Redirect::permanent("/v2/") }))
.nest("/api/v1/", api.to_router().with_state(self.clone()))
.route("/api/v1", get(|| async { Redirect::permanent("/api/v1/") }))
.layer(axum::middleware::map_response_with_state(
self,
response::append_info_headers,
Expand All @@ -181,8 +176,8 @@ fn info() -> openapiv3::v3_1::Info {
use openapiv3::v3_1::{Contact, License};

openapiv3::v3_1::Info {
title: "Iota Node Api".to_owned(),
description: Some("REST Api for interacting with the Iota Blockchain".to_owned()),
title: "IOTA Node API".to_owned(),
description: Some("REST API for interacting with the IOTA Blockchain".to_owned()),
contact: Some(Contact {
name: Some("IOTA Foundation".to_owned()),
url: Some("https://github.com/iotaledger/iota".to_owned()),
Expand All @@ -198,10 +193,6 @@ fn info() -> openapiv3::v3_1::Info {
}
}

async fn redirect(axum::extract::Path(path): axum::extract::Path<String>) -> Redirect {
Redirect::permanent(&format!("/v2/{path}"))
}

mod _schemars {
use schemars::{
JsonSchema,
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-rest-api/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'a, S> Api<'a, S> {
openapi.tags.sort_by(|a, b| a.name.cmp(&b.name));

openapi.servers = vec![openapiv3::v3_1::Server {
url: "/v2".into(),
url: "/api/v1".into(),
..Default::default()
}];

Expand Down
2 changes: 1 addition & 1 deletion crates/iota-single-node-benchmark/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Iota Single Node Benchmark

This crate contains a binary for performance benchmarking a single Iota node.
This crate contains a binary for performance benchmarking a single IOTA node.
Upon running the binary, the node will instantiate a standalone `AuthorityState`, and submit
executable transactions to it in parallel. We then measure the time it takes for it to finish
executing all the transactions.
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-swarm-config/src/node_config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl ValidatorConfigBuilder {
indexer_max_subscriptions: Default::default(),
transaction_kv_store_read_config: Default::default(),
transaction_kv_store_write_config: None,
enable_experimental_rest_api: true,
enable_rest_api: true,
jwk_fetch_interval_seconds: self
.jwk_fetch_interval
.map(|i| i.as_secs())
Expand Down Expand Up @@ -497,7 +497,7 @@ impl FullnodeConfigBuilder {
indexer_max_subscriptions: Default::default(),
transaction_kv_store_read_config: Default::default(),
transaction_kv_store_write_config: Default::default(),
enable_experimental_rest_api: true,
enable_rest_api: true,
// note: not used by fullnodes.
jwk_fetch_interval_seconds: 3600,
zklogin_oauth_providers: default_zklogin_oauth_providers(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ validator_configs:
db-path: /tmp/foo/
network-address: ""
json-rpc-address: "0.0.0.0:1"
enable-experimental-rest-api: true
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
consensus-config:
Expand Down Expand Up @@ -134,7 +134,7 @@ validator_configs:
db-path: /tmp/foo/
network-address: ""
json-rpc-address: "0.0.0.0:1"
enable-experimental-rest-api: true
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
consensus-config:
Expand Down Expand Up @@ -254,7 +254,7 @@ validator_configs:
db-path: /tmp/foo/
network-address: ""
json-rpc-address: "0.0.0.0:1"
enable-experimental-rest-api: true
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
consensus-config:
Expand Down Expand Up @@ -374,7 +374,7 @@ validator_configs:
db-path: /tmp/foo/
network-address: ""
json-rpc-address: "0.0.0.0:1"
enable-experimental-rest-api: true
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
consensus-config:
Expand Down Expand Up @@ -494,7 +494,7 @@ validator_configs:
db-path: /tmp/foo/
network-address: ""
json-rpc-address: "0.0.0.0:1"
enable-experimental-rest-api: true
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
consensus-config:
Expand Down Expand Up @@ -614,7 +614,7 @@ validator_configs:
db-path: /tmp/foo/
network-address: ""
json-rpc-address: "0.0.0.0:1"
enable-experimental-rest-api: true
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
consensus-config:
Expand Down Expand Up @@ -734,7 +734,7 @@ validator_configs:
db-path: /tmp/foo/
network-address: ""
json-rpc-address: "0.0.0.0:1"
enable-experimental-rest-api: true
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
consensus-config:
Expand Down
1 change: 0 additions & 1 deletion crates/iota-tool/src/db_tool/db_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub enum StoreName {
Validator,
Index,
Epoch,
// TODO: Add the new checkpoint v2 tables.
}
impl std::fmt::Display for StoreName {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion docker/pg-services-local/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
- "127.0.0.1:9000:9000"
- "127.0.0.1:9123:9123"
healthcheck:
test: "curl -f http://local-network:9000/rest/"
test: "curl -f http://local-network:9000/api/v1/"
interval: 1s
start_period: 5s
timeout: 2s
Expand Down
Loading