Add API versioning
arnaucube root@arnaucube.com
Mon, 22 Mar 2021 11:53:24 +0100
3 files changed,
31 insertions(+),
29 deletions(-)
M
api/api.go
→
api/api.go
@@ -50,38 +50,40 @@ chainID: consts.ChainID,
hermezAddress: consts.HermezAddress, } + v1 := server.Group("/v1") + // Add coordinator endpoints if coordinatorEndpoints { // Account - server.POST("/account-creation-authorization", a.postAccountCreationAuth) - server.GET("/account-creation-authorization/:hezEthereumAddress", a.getAccountCreationAuth) + v1.POST("/account-creation-authorization", a.postAccountCreationAuth) + v1.GET("/account-creation-authorization/:hezEthereumAddress", a.getAccountCreationAuth) // Transaction - server.POST("/transactions-pool", a.postPoolTx) - server.GET("/transactions-pool/:id", a.getPoolTx) + v1.POST("/transactions-pool", a.postPoolTx) + v1.GET("/transactions-pool/:id", a.getPoolTx) } // Add explorer endpoints if explorerEndpoints { // Account - server.GET("/accounts", a.getAccounts) - server.GET("/accounts/:accountIndex", a.getAccount) - server.GET("/exits", a.getExits) - server.GET("/exits/:batchNum/:accountIndex", a.getExit) + v1.GET("/accounts", a.getAccounts) + v1.GET("/accounts/:accountIndex", a.getAccount) + v1.GET("/exits", a.getExits) + v1.GET("/exits/:batchNum/:accountIndex", a.getExit) // Transaction - server.GET("/transactions-history", a.getHistoryTxs) - server.GET("/transactions-history/:id", a.getHistoryTx) + v1.GET("/transactions-history", a.getHistoryTxs) + v1.GET("/transactions-history/:id", a.getHistoryTx) // Status - server.GET("/batches", a.getBatches) - server.GET("/batches/:batchNum", a.getBatch) - server.GET("/full-batches/:batchNum", a.getFullBatch) - server.GET("/slots", a.getSlots) - server.GET("/slots/:slotNum", a.getSlot) - server.GET("/bids", a.getBids) - server.GET("/state", a.getState) - server.GET("/config", a.getConfig) - server.GET("/tokens", a.getTokens) - server.GET("/tokens/:id", a.getToken) - server.GET("/coordinators", a.getCoordinators) + v1.GET("/batches", a.getBatches) + v1.GET("/batches/:batchNum", a.getBatch) + v1.GET("/full-batches/:batchNum", a.getFullBatch) + v1.GET("/slots", a.getSlots) + v1.GET("/slots/:slotNum", a.getSlot) + v1.GET("/bids", a.getBids) + v1.GET("/state", a.getState) + v1.GET("/config", a.getConfig) + v1.GET("/tokens", a.getTokens) + v1.GET("/tokens/:id", a.getToken) + v1.GET("/coordinators", a.getCoordinators) } return a, nil
M
api/api_test.go
→
api/api_test.go
@@ -40,8 +40,8 @@ Len() int
New() Pendinger } -const apiAddr = ":4010" -const apiURL = "http://localhost" + apiAddr + "/" +const apiPort = "4010" +const apiURL = "http://localhost:" + apiPort + "/v1/" var SetBlockchain = ` Type: Blockchain@@ -258,7 +258,7 @@ log.Error(err)
panic(err) } // Start server - listener, err := net.Listen("tcp", apiAddr) //nolint:gosec + listener, err := net.Listen("tcp", ":"+apiPort) //nolint:gosec if err != nil { panic(err) }@@ -622,7 +622,7 @@ // API
apiGinTO := gin.Default() finishWait := make(chan interface{}) startWait := make(chan interface{}) - apiGinTO.GET("/wait", func(c *gin.Context) { + apiGinTO.GET("/v1/wait", func(c *gin.Context) { cancel, err := apiConnConTO.Acquire() defer cancel() require.NoError(t, err)@@ -650,9 +650,9 @@ )
require.NoError(t, err) client := &http.Client{} - httpReq, err := http.NewRequest("GET", "http://localhost:4444/tokens", nil) + httpReq, err := http.NewRequest("GET", "http://localhost:4444/v1/tokens", nil) require.NoError(t, err) - httpReqWait, err := http.NewRequest("GET", "http://localhost:4444/wait", nil) + httpReqWait, err := http.NewRequest("GET", "http://localhost:4444/v1/wait", nil) require.NoError(t, err) // Request that will get timed out var wg sync.WaitGroup
M
api/swagger.yml
→
api/swagger.yml
@@ -60,9 +60,9 @@ description: Find out more about Hermez network.
url: 'https://hermez.io' servers: - description: Hosted mock up - url: https://apimock.hermez.network + url: https://apimock.hermez.network/v1 - description: Localhost mock Up - url: http://localhost:4010 + url: http://localhost:4010/v1 tags: - name: Coordinator description: Endpoints used by the nodes running in coordinator mode. They are used to interact with the network.