bigchaindb/bigchaindb/web/views/info.py

58 lines
1.7 KiB
Python
Raw Normal View History

# Copyright © 2020 Interplanetary Database Association e.V.,
# BigchainDB and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
"""API Index endpoint"""
import flask
2017-01-05 13:31:05 +01:00
from flask_restful import Resource
2017-06-14 11:09:42 +02:00
from bigchaindb.web.views.base import base_ws_uri
from bigchaindb import version
2017-04-07 14:57:11 +02:00
from bigchaindb.web.websocket_server import EVENTS_ENDPOINT
2017-01-06 14:18:10 +01:00
class RootIndex(Resource):
2017-01-05 13:31:05 +01:00
def get(self):
2017-01-06 14:45:38 +01:00
docs_url = [
'https://docs.bigchaindb.com/projects/server/en/v',
version.__version__ + '/'
2017-01-06 14:45:38 +01:00
]
2017-01-05 13:31:05 +01:00
return flask.jsonify({
'api': {
2017-06-14 11:09:42 +02:00
'v1': get_api_v1_info('/api/v1/')
2017-01-06 14:45:38 +01:00
},
'docs': ''.join(docs_url),
2017-01-05 13:31:05 +01:00
'software': 'BigchainDB',
'version': version.__version__,
})
2017-01-06 14:18:10 +01:00
class ApiV1Index(Resource):
def get(self):
2017-06-14 11:09:42 +02:00
return flask.jsonify(get_api_v1_info('/'))
2017-06-14 11:09:42 +02:00
def get_api_v1_info(api_prefix):
"""Return a dict with all the information specific for the v1 of the
api.
"""
websocket_root = base_ws_uri() + EVENTS_ENDPOINT
docs_url = [
'https://docs.bigchaindb.com/projects/server/en/v',
version.__version__,
'/http-client-server-api.html',
]
return {
'docs': ''.join(docs_url),
2017-06-14 11:09:42 +02:00
'transactions': '{}transactions/'.format(api_prefix),
'blocks': '{}blocks/'.format(api_prefix),
2017-06-14 11:09:42 +02:00
'assets': '{}assets/'.format(api_prefix),
'outputs': '{}outputs/'.format(api_prefix),
'streams': websocket_root,
'metadata': '{}metadata/'.format(api_prefix),
'validators': '{}validators'.format(api_prefix),
}