inveniosoftware / inveniosoftware/flask-resources
[Suggestion] ResourceConfig refactor
- Dominant language
- Python
- Stars
- 3
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Description
I think ResourceConfig can be improved:
1- `ResourceConfig` is starting to accumulate a [hodgepodge](https://github.com/inveniosoftware/flask-resources/blob/master/flask_resources/resources.py#L78-L110) of [fields](https://github.com/inveniosoftware/invenio-records-resources/blob/master/invenio_records_resources/resources/records/config.py#L32-L47), but these are not quite organized, making it hard to navigate the configuration (especially for developers making an API using this library) and extend it without being overwhelmed.
2- Some custom classes/objects are needed in the configuration which adds to the difficulty of navigating it and creating it. Some we have no choice (Any Serializer/Deserializer), but others we could potentially remove *from the config* (only for now).
Here is my suggestion for the refactor of ResourceConfig taken from https://gist.github.com/fenekku/69b49923816cd9ab160aa46f0a70f1e3#file-resources-py-L13-L49
```python
class ResourceConfig:
# Suggested
item_route = "/resources/" # or request_item_route . These 2 don't matter too much to me
list_route = "/resources/"
## incoming
request_url_args_parser = ArgsParser() # Could be renamed ArgsDeserializer()
# OR
request_url_args_parser = {
"create": ArgsParser() # any of the resource method can be listed
}
request_body_deserializer = [JSONDeserializer(mimetype="application/json"),],
# OR
request_body_deserializer = {
"create": [JSONDeserializer(mimetype="application/json"),]
}
# Wouldn't worry about implementing this one until we actually need it
request_headers_deserializer = [HeadersDeserializer(),],
# OR
request_headers_deserializer = {
"create": [HeadersDeserializer(),]
}
## outgoing
# Optional and again would wait until needed to implement
response_headers_serializer = HeadersSerializer(override=False)
# OR
response_headers_serializer = {
'create': HeadersSerializer(override=False) # Optional
}
response_body_serializer = [JSONSerializer(mimetype="application/json"),]
# or
response_body_serializer = {
'create': [JSONSerializer(mimetype="application/json"),]
}
```
Nice things:
- The symmetry between request and response is evident.
- Developers can cater to specific Resource methods
- Only Serializers/Deserializers need to be provided: no other custom objects.
This issue combines: https://github.com/inveniosoftware/flask-resources/issues/39 and https://github.com/inveniosoftware/flask-resources/issues/40 (which were both started from comments I made).
Contributor guide
Research direction
Start by reviewing ResourceConfig in flask_resources/resources.py and the related configuration in invenio_records_resources/resources/records/config.py. Read the linked issues 39 and 40 and compare the proposed structure in the referenced gist. Done requires an agreed refactor scope and a consistent configuration design, but the issue does not define the final behavior or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend-api-design
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100