Первоначально я написал webservice
, чтобы разрешить использование методов GET и POST
на всех конечных точках. Теперь в нашем рабочем процессе веб-сервисов есть некоторые изменения: мы хотим заблокировать конечную точку POST
для некоторых конечных точек и включить для них PUT
, для некоторых конечных точек по-прежнему будет включена POST
.
Я объясню больше, добавив фрагмент кода settings.py
__author__ = 'sappal'
# pulling DBSchema from DBTableSchema
from DBSchema.DBTableSchema import DBTableSchema
from Configs import Configs
dbtableSchema = DBTableSchema()
# Let's just use the local mongod instance. Edit as needed.
# Please note that MONGO_HOST and MONGO_PORT could very well be left
# out as they already default to a bare bones local 'mongod' instance.
## LOCALHOST ENTRIES
MONGO_HOST = Configs.MONGO_DB_HOST
MONGO_PORT = Configs.MONGO_DB_PORT
MONGO_USERNAME = Configs.MONGO_DB_USER_NAME
MONGO_PASSWORD = Configs.MONGO_DB_PASSWORD
MONGO_DBNAME = Configs.MONGO_DB
# Enable reads (GET), inserts (POST) and DELETE for resources/collections
# (if you omit this line, the API will default to ['GET'] and provide
# read-only access to the endpoint).
RESOURCE_METHODS = ['GET', 'PATCH', 'POST', 'DELETE']
# Enable reads (GET), edits (PATCH), replacements (PUT) and deletes of
# individual items (defaults to read-only item access).
ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE', 'POST']
# Used for implementing user-resource restricted access.
# Returns the documents which are associated with particular user
AUTH_FIELD = 'userid'
people = {
'item_title': 'person',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'POST'],
'schema': dbtableSchema.schema_people,
'public_methods': ['POST']
}
org = {
'item_title': 'org',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'PATCH'],
'schema': dbtableSchema.schema_people_org
}
puburl = {
'item_title': 'puburl',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'PATCH'],
'schema': dbtableSchema.schema_people_pub_url
}
address = {
'item_title': 'address',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'PATCH'],
'schema': dbtableSchema.schema_people_address
}
contactnumber = {
'item_title': 'contactnumber',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'PATCH'],
'schema': dbtableSchema.schema_people_contact_number
}
template = {
'item_title': 'template',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'POST'],
'schema': dbtableSchema.schema_template
}
usersharedcontacts = {
'item_title': 'usersharedcontacts',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'PATCH'],
'schema': dbtableSchema.schema_people_with_user_shared_contacts
}
cardholder = {
'item_title': 'cardholder',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'PATCH'],
'schema': dbtableSchema.schema_people_card_holder
}
DOMAIN = {
'people': people,
'org': org,
'puburl': puburl,
'address': address,
'contactnumber': contactnumber,
'template': template,
'usersharedcontacts': usersharedcontacts,
'cardholder': cardholder
}
Я хочу включить метод POST
для конечных точек people
и template
, как видите, я сделал эту конфигурацию 'resource_methods': ['GET', 'POST']
для указанных выше конечных точек.
Я также хочу отключить метод POST
для оставшихся конечных точек, поэтому я настроил для оставшихся конечных точек 'resource_methods': ['GET', 'PATCH'],
следующее.
Я также настроил RESOURCE_METHODS = ['GET', 'PATCH', 'POST', 'DELETE']
Но когда я пытаюсь запустить приложение, я получаю ошибки на консоли следующего типа
eve.exceptions.ConfigException: Unallowed [usersharedcontacts] resource method(s): PATCH. Supported: GET, POST, DELETE
Process finished with exit code 1