mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
/api/v1/ informational endpoint
This commit is contained in:
parent
f9ed5690a7
commit
80f3bb3809
@ -17,6 +17,7 @@ def r(*args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
ROUTES_API_V1 = [
|
ROUTES_API_V1 = [
|
||||||
|
r('/', info.ApiV1Index),
|
||||||
r('transactions/<string:tx_id>', tx.TransactionApi),
|
r('transactions/<string:tx_id>', tx.TransactionApi),
|
||||||
r('transactions/<string:tx_id>/status', tx.TransactionStatusApi),
|
r('transactions/<string:tx_id>/status', tx.TransactionStatusApi),
|
||||||
r('transactions', tx.TransactionListApi),
|
r('transactions', tx.TransactionListApi),
|
||||||
@ -25,6 +26,6 @@ ROUTES_API_V1 = [
|
|||||||
|
|
||||||
|
|
||||||
API_SECTIONS = [
|
API_SECTIONS = [
|
||||||
(None, [r('/', info.IndexApi)]),
|
(None, [r('/', info.RootIndex)]),
|
||||||
('/api/v1/', ROUTES_API_V1),
|
('/api/v1/', ROUTES_API_V1),
|
||||||
]
|
]
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
from flask import jsonify
|
"""
|
||||||
|
Common classes and methods for API handlers
|
||||||
|
"""
|
||||||
|
|
||||||
|
from flask import jsonify, request
|
||||||
|
|
||||||
|
|
||||||
def make_error(status_code, message=None):
|
def make_error(status_code, message=None):
|
||||||
|
|
||||||
if status_code == 404 and message is None:
|
if status_code == 404 and message is None:
|
||||||
message = 'Not found'
|
message = 'Not found'
|
||||||
|
|
||||||
@ -12,3 +15,8 @@ def make_error(status_code, message=None):
|
|||||||
})
|
})
|
||||||
response.status_code = status_code
|
response.status_code = status_code
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def base_url():
|
||||||
|
return '%s://%s/' % (request.environ['wsgi.url_scheme'],
|
||||||
|
request.environ['HTTP_HOST'])
|
||||||
|
@ -4,10 +4,11 @@ import flask
|
|||||||
from flask_restful import Resource
|
from flask_restful import Resource
|
||||||
|
|
||||||
import bigchaindb
|
import bigchaindb
|
||||||
|
from bigchaindb.web.views.base import base_url
|
||||||
from bigchaindb import version
|
from bigchaindb import version
|
||||||
|
|
||||||
|
|
||||||
class IndexApi(Resource):
|
class RootIndex(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
return flask.jsonify({
|
return flask.jsonify({
|
||||||
'software': 'BigchainDB',
|
'software': 'BigchainDB',
|
||||||
@ -15,3 +16,21 @@ class IndexApi(Resource):
|
|||||||
'public_key': bigchaindb.config['keypair']['public'],
|
'public_key': bigchaindb.config['keypair']['public'],
|
||||||
'keyring': bigchaindb.config['keyring']
|
'keyring': bigchaindb.config['keyring']
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
class ApiV1Index(Resource):
|
||||||
|
def get(self):
|
||||||
|
api_root = base_url() + 'api/v1/'
|
||||||
|
docs_url = ['https://docs.bigchaindb.com/projects/server/en/',
|
||||||
|
version.__short_version__,
|
||||||
|
'/drivers-clients/http-client-server-api.html',
|
||||||
|
]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"_links": {
|
||||||
|
"docs": {"href": ''.join(docs_url)},
|
||||||
|
"self": {"href": api_root},
|
||||||
|
"statuses": {"href": api_root + "statuses/"},
|
||||||
|
"transactions": {"href": api_root + "transactions/"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -1,5 +1,25 @@
|
|||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
|
||||||
def test_api_root_url_shows_basic_info(client):
|
def test_api_root_url_shows_basic_info(client):
|
||||||
from bigchaindb import version
|
from bigchaindb import version
|
||||||
res = client.get('/')
|
res = client.get('/')
|
||||||
assert res.json['software'] == 'BigchainDB'
|
assert res.json['software'] == 'BigchainDB'
|
||||||
assert res.json['version'] == version.__version__
|
assert res.json['version'] == version.__version__
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_v1_endpoint(client):
|
||||||
|
with mock.patch('bigchaindb.version.__short_version__', 'tst'):
|
||||||
|
res = client.get('/api/v1')
|
||||||
|
docs_url = ['https://docs.bigchaindb.com/projects/server/en/',
|
||||||
|
'tst',
|
||||||
|
'/drivers-clients/http-client-server-api.html',
|
||||||
|
]
|
||||||
|
assert res.json == {
|
||||||
|
'_links': {
|
||||||
|
'docs': {'href': ''.join(docs_url)},
|
||||||
|
'self': {'href': 'http://localhost/api/v1/'},
|
||||||
|
'statuses': {'href': 'http://localhost/api/v1/statuses/'},
|
||||||
|
'transactions': {'href': 'http://localhost/api/v1/transactions/'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user