certichain

Blockchain built from scratch for verifying document's legitimacy.
Log | Files | Refs | README | LICENSE

router.go (1588B)


      1 // Copyright 2026 Shivakumar (Certichain)
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 package api
     16 
     17 import (
     18 	"net/http"
     19 
     20 	"certichain/api/handlers"
     21 )
     22 
     23 // NewRouter registers every route and returns a composed handlers.
     24 func NewRouter(deps Deps) http.Handler {
     25 	mux := http.NewServeMux()
     26 
     27 	mux.HandleFunc("GET /healthz", handlers.Health())
     28 	mux.HandleFunc("POST /v1/institutions", handlers.RegisterInstitution(deps.Registry))
     29 	mux.HandleFunc("GET /v1/institutions/{did}", handlers.GetInstitution(deps.Registry))
     30 	mux.HandleFunc("POST /v1/transactions", handlers.SubmitTransaction(deps.Mempool, deps.Registry))
     31 	mux.HandleFunc("GET /v1/transactions/{tx_id}", handlers.GetTransaction(deps.Mempool, deps.Blockchain))
     32 	mux.HandleFunc("GET /v1/blocks/{hash}", handlers.GetBlock(deps.Blockchain))
     33 	mux.HandleFunc("GET /v1/blocks/height/{height}", handlers.GetBlockByHeight(deps.Blockchain))
     34 	mux.HandleFunc("GET /v1/blocks/latest", handlers.GetLatestBlock(deps.Blockchain))
     35 	mux.HandleFunc("GET /v1/verify/{tx_id}", handlers.Verify(deps.Blockchain, deps.Registry))
     36 
     37 	return mux
     38 }