src/Server/Node/API/HeaderAPI.cpp
//
// Handles requests to retrieve a single header by hash, height, or output commitment.
//
// APIs:
// GET /v1/headers/<hash>
// GET /v1/headers/<height>
// GET /v1/headers/<output commit>
//
Handles requests to retrieve a single header by hash, height, or output commitment.
Handles requests to retrieve a single header by hash height or output commitment .
int HeaderAPI::GetHeader_Handler(struct mg_connection* conn, void* pNodeContext)
{
	const std::string requestedHeader = HTTPUtil::GetURIParam(conn, "/v1/headers/");
	auto pBlockHeader = GetHeader(requestedHeader, ((NodeContext*)pNodeContext)->m_pBlockChainServer);
	if (nullptr != pBlockHeader)
	{
		const Json::Value headerNode = JSONFactory::BuildHeaderJSON(*pBlockHeader);
		return HTTPUtil::BuildSuccessResponse(conn, headerNode.toStyledString());
	}
	else
	{
		const std::string response = "HEADER NOT FOUND";
		return HTTPUtil::BuildBadRequestResponse(conn, response);
	}
}
int HeaderAPI :: GetHeader_Handler ( struct mg_connection * conn , void * pNodeContext ) { const std :: string requestedHeader = HTTPUtil :: GetURIParam ( conn , " " ) ; auto pBlockHeader = GetHeader ( requestedHeader , ( ( NodeContext * ) pNodeContext ) -> m_pBlockChainServer ) ; if ( nullptr != pBlockHeader ) { const Json :: Value headerNode = JSONFactory :: BuildHeaderJSON ( * pBlockHeader ) ; return HTTPUtil :: BuildSuccessResponse ( conn , headerNode . toStyledString ( ) ) ; } else { const std :: string response = " " ; return HTTPUtil :: BuildBadRequestResponse ( conn , response ) ; } }
Handles requests to retrieve a single header by hash, height, or output commitment.
Handles requests to retrieve a single header by hash height or output commitment .