GithubHelp home page GithubHelp logo

restfly's Introduction

RESTfly: Simplifying API Libraries

RESTfly (pronounced restfully) is a framework for building libraries to easily interact with RESTful APIs.

https://sonarcloud.io/api/project_badges/measure?project=librestfly_restfly&metric=alert_status

https://restfly.readthedocs.io/en/latest/_static/logo.png

RESTfly is a simple library designed to provide the scaffolding to make API interaction libraries for just about any RESTful API. With an emphasis on simplicity and readability of the resulting library code thats written, the idea here is provide something that is not only useful for folks to use, but can also serve as a reference implementation of the given APIs.

Please refer to the full documentation at https://restfly.readthedocs.io.

restfly's People

Contributors

stevemcgrath avatar rogdham avatar kalidor avatar

Stargazers

 avatar Felix Zenk avatar Cüneyt Yıldız avatar William Guilherme avatar Aseem Savio avatar  avatar Erwan Tonnerre avatar Michael Resnick avatar Jacob Gårder avatar  avatar  avatar  avatar Mitch Kelly avatar  avatar

Watchers

 avatar Rahul Shelke avatar Mitch Kelly avatar John Lampe avatar Jacob Gårder avatar

restfly's Issues

Tox is not working anymore

Since 4694684 the file test-requirements.txt does not exist, so running tox on the repository does not work anymore:

$ tox -e py38
GLOB sdist-make: /restfly/setup.py
py38 create: /restfly/.tox/py38
py38 installdeps: -rtest-requirements.txt
ERROR: invocation failed (exit code 1), logfile: /restfly/.tox/py38/log/py38-1.log
======================================================================= log start ========================================================================
ERROR: Could not open requirements file: [Errno 2] Aucun fichier ou dossier de ce type: 'test-requirements.txt'
WARNING: You are using pip version 21.3.1; however, version 22.0.2 is available.
You should consider upgrading via the '/restfly/.tox/py38/bin/python -m pip install --upgrade pip' command.

======================================================================== log end =========================================================================
ERROR: could not install deps [-rtest-requirements.txt]; v = InvocationError('/restfly/.tox/py38/bin/python -m pip install -rtest-requirements.txt', 1)
________________________________________________________________________ summary _________________________________________________________________________
ERROR:   py38: could not install deps [-rtest-requirements.txt]; v = InvocationError('/restfly/.tox/py38/bin/python -m pip install -rtest-requirements.txt', 1)

Feature Request: Automatically return BoxList if response contains a list.

What is happening

When Box is enabled, all responses with a JSON content-type are assumed to be a dict. This causes an exception from box when an API returns a list with content-type JSON:

box.exceptions.BoxError: json data not returned as a dictionary, but rather a list

We can overcome this by specifying box=BoxList when sending the request from the APIEndpoint method. This can be slightly onerous as we need to import BoxList into our APIEndpoint modules and then specify box=BoxList for every method that we expect a list from.

Some API responses can return content-type JSON as either a dict or list, which requires us to test for that and have a conditional return.

What would be nice

If Restfly could automatically return a Box for dict or BoxList for list.

Idea for implementation:

Modify session.py
https://github.com/SteveMcGrath/restfly/blob/c899d89b90aa7da2c1c01e239126e7df4b59619f/restfly/session.py#L575-L585

Modified session.py

                    if box and 'application/json' in ctype:
                        # we want to make a quick check to ensure that there is
                        # actually some data to pass to Box.  If there isn't,
                        # then we should just return back a None response.
                        if len(resp.text) > 0:
                            if box_attrs.get('default_box'):
                                self._log.debug(
                                    'unknown attrs will return as %s' %
                                    box_attrs.get('default_box_attr', Box)
                                )
                            try:
                                return box.from_json(resp.text, **box_attrs)
                            except BoxError:
                                return BoxList(json.loads(resp.text))

Let me know what you think?

Support user-supplied hooks for customized logging, progress tracking, etc..

hey @SteveMcGrath you may remember be from over @ https://github.com/tenable/pyTenable

I sent in this PR which was very useful to me in tracking the progress of very large downloads. I stumbled across RestFLY after seeing your response to a separate pyTenable issue and thought I might mention this here in case you found it to be worthwhile. It would be nice if you made inserting hooks at various layers easy, for things like tracking the progress of a page iterator, or a download/upload stream

In some cases of course this is just a matter of designing the class so that it's easy for the user to instrument the iteration; in some other cases it's a more low-level thing, like the PR above, where the iter_content() of the requests.Response object was handled directly by the hook

I haven't looked much at RestFLY yet, but I'm now pretty familiar with the iterators in pyTenable and see it's very similar. I wish I had come across your project about 2 years ago as I ended up writing something very similar- though admittedly a bit uglier, and with a nasty case of creeping featurism

Please feel free to close this out after reading it. I'm not sure if it will be interesting to you or not

EDIT: I also ended up implementing a class ParallelExportsIterator(APIResultsIterator) to parallelize downloading chunks from certain exports endpoints. That one is very ugly but it works. Just another idea on how you might want to extend RestFLY, or keep in mind how others may want to extend it while you're developing it

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.