Coder Social home page Coder Social logo

rest's People

Contributors

gi0baro avatar josejachuf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rest's Issues

Creating Nested Schema and Schema Not associated with Model

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?

About query language

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

Deprecated notification with emmet 2.1

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

Congratulations

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

update_values rules in models

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

Help with Query Language

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%" }}]

[openapi] Export api doc to pdf

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

[1] https://github.com/mrin9/RapiPdf

Posible bug in parse_params

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

[openapi] json error with security_schemes

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

Using cache

Hi @gi0baro,

Is there any way to use cache without explicitly defining index and read methods?

Integrate swagger

These days I was watching FastApi and I really liked the self-documentation. I have these doubts:

  1. How complicated can it be to integrate Swagger into emmett-rest?
  2. If it were integrated, would it be through an extension?
    Best regards
    Jose

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.