emmett-framework / rest Goto Github PK
View Code? Open in Web Editor NEWREST extension for Emmett framework
License: BSD 3-Clause "New" or "Revised" License
REST extension for Emmett framework
License: BSD 3-Clause "New" or "Revised" License
How can we create nested json schema with emmett_rest? For example, data from more than one model or data from more than one related Model? Also, why it is mandatory to have return data from an endpoint only associated with a Model?
tasks = app.rest_module(__name__, 'api_task', Task, url_prefix='tasks')
Here, if the json data is not associated with any Model, how can I use this extension?
Hi @gi0baro
Similar to how it was before this patch [1], when I use
@openapi.include
this [2]
When the app has url_prefix, this is not being included in the paths generated.
I tried to solve it, but I didn't know how to do it
[1] #12
[2] https://github.com/emmett-framework/rest#openapi-decorators
Hi @gi0baro . Dependence fails when updating EMMETT to Version 2.2
Jose
Hi @gi0baro
I am trying to use where with $or and $and but it doesn't work as I hope
in javascript I have:
if (params.filter) {
where = {
$or: [
{
// id: params.filter,
last_name: { $ilike: params.filter },
first_name: { $ilike: params.filter }
}
]
}
where = JSON.stringify(where)
}
With this I get, for example:
{"$or":[{"last_name":{"$ilike":"Fue"},"first_name":{"$ilike":"Fue"}}]}
then:
http://a.com/api/user?page=1&page_size=20&sort_by=-id&where={"$or":[{"last_name":{"$ilike":"F"},"first_name":{"$ilike":"F"}}]}
but not returns data
What am I doing wrong?
Jose
Hi @gi0baro
/venv/lib/python3.8/site-packages/emmett_rest/ext.py:59: RemovedInNextVersionWarning: extensions.listen_signal str argument is deprecated, use extensions.Signals as argument instead.
@listen_signal('before_database')
Jose
Thank you. Excellent work.
I am a user of weppy-REST and I see, in a first quick read, that emmett-REST already solves almost all the common situations in which you had to write a little more code in w-rest. I'm going to try it more carefully in some app that I have working.
The first thing that caught my attention were the queries and additional routes
regards
Hi,
All the following happens to me using the latest versions of Emmett and Emmett Rest:
emmett 2.5.6
emmett-crypto 0.5.1
emmett-rest 1.5.2
All my models inherit from Signature
class TimeStamp(Model):
created_at = Field('datetime')
updated_at = Field('datetime')
default_values = {
'created_at': lambda: local_now(),
'updated_at': lambda: local_now(),
}
update_values = {
'updated_at': lambda: local_now(),
}
class Signature(TimeStamp):
refers_to(
{'created_by': 'User'},
{'updated_by': 'User'}
)
default_values = {
'created_by': lambda: get_user(),
'updated_by': lambda: get_user(),
}
update_values = {
'updated_by': lambda: get_user(),
}
What I am seeing that I have update a record from the API Rest, the updates are not worked, this is updated_at and updated_by maintain the value of when the record was created
Hi,
This works:
http://localhost:8000/main/api/v1/myapy?where={"myfield": "Carlos"}
Returns to me the records that meet the condition.
This does not work, nothing returns me:
http://localhost:8000/main/api/v1/myapy?where={"myfield": { "$ilike": "%Carlos%" }}
{
"data": [],
"meta": {
"object": "list",
"has_more": false,
"total_objects": 0
}
}
In an older version of Emmett and Emmett Rest something like this did work
$or: [{ myfield: { $ilike: "%Carlos%" }}, {another_field: { $ilike: "%Carlos%" }}]
I share a simple way to export the documentation to PDF using rapipdf [1].
You must export the documentation to YAML and then use it with
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/rapipdf/dist/rapipdf-min.js"></script>
</head>
<body>
<rapi-pdf style="width:700px; height:40px; font-size:18px;" spec-url="openapi.yaml" >
</rapi-pdf>
</body>
</html>
Or use it online from: http://127.0.0.1:8000/main/openapi.yaml
Best regards
Jose
I try with:
contact = {
"name": "API Support",
"url": "http://www.example.com/support",
"email": "[email protected]"
}
But I don't see it in the documentation
Hi @gi0baro
it seems to me that there is a bug in parse_params. Maybe I am doing something wrong, but with the following it does not work
@users.update()
async def user_edit(dbset, rid):
attrs = await users.parse_params()
body_params = await request.body_params
print(attrs, body_params)
attrs is always empty. I put the also the request.body_params to check
The output of the print is:
<sdict {}> <sdict {'id': 3, 'registration_key': 'blocked'}>
Best regards
Jose
An error occurs when generating the JSON when the data of security_schemes is included. For Yaml and HTML it works fine.
security_schemes = {
"Bearer": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT",
}
,
"BasicAuth": {
"type": "http",
"scheme": "basic"
}
}
Traceback (most recent call last):
File "/venv/lib/python3.8/site-packages/emmett/asgi/handlers.py", line 325, in dynamic_handler
http = await self.router.dispatch(ctx.request, ctx.response)
File "/venv/lib/python3.8/site-packages/emmett/routing/router.py", line 249, in dispatch
return await match.dispatch(reqargs, response)
File "/venv/lib/python3.8/site-packages/emmett/routing/dispatchers.py", line 72, in dispatch
rv = self.response_builder(await self.f(**reqargs), response)
File "/venv/lib/python3.8/site-packages/emmett/pipeline.py", line 328, in flow
output = await pipe_method(f, **kwargs)
File "/venv/lib/python3.8/site-packages/emmett/pipeline.py", line 234, in pipe
return await next_pipe(**kwargs)
File "/venv/lib/python3.8/site-packages/emmett/pipeline.py", line 328, in flow
output = await pipe_method(f, **kwargs)
File "/venv/lib/python3.8/site-packages/emmett/tools/auth/apis.py", line 277, in pipe
return await next_pipe(**kwargs)
File "/venv/lib/python3.8/site-packages/emmett/pipeline.py", line 369, in flow
return await pipe_method(f, **kwargs)
File "/venv/lib/python3.8/site-packages/emmett/tools/service.py", line 28, in pipe_request
return self.encoder(await next_pipe(**kwargs))
File "/venv/lib/python3.8/site-packages/emmett/serializers.py", line 55, in _json_default
raise TypeError
TypeError
Hi @gi0baro ,
upgrade is needed so that it doesn't protest the version of emmett
Hi @gi0baro,
Is there any way to use cache without explicitly defining index and read methods?
Related to emmett-framework/emmett#453
These days I was watching FastApi and I really liked the self-documentation. I have these doubts:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.