Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96825

Re: Writing a module to abstract a REST api

Path csiph.com!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <jcasale@activenetwerx.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'static': 0.03; 'api.': 0.04; 'classes.': 0.07; 'api': 0.09; '(without': 0.09; 'frameworks,': 0.09; 'here?': 0.09; 'subject:Writing': 0.09; 'subject:module': 0.09; 'thread': 0.10; 'python': 0.10; 'skip:f 30': 0.15; 'globals.': 0.16; 'interacting': 0.16; 'received:172.18.0': 0.16; 'subject:api': 0.16; 'to:name:python- list@python.org': 0.20; 'to:2**1': 0.21; 'tuples': 0.22; "python's": 0.23; 'thus': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'example': 0.26; 'rest': 0.26; 'module.': 0.27; 'skip:( 20': 0.28; 'container': 0.29; 'initialized': 0.29; 'queue': 0.29; 'workaround': 0.29; 'objects': 0.29; 'work.': 0.30; 'call.': 0.30; 'query': 0.30; 'option': 0.31; 'returned': 0.32; 'class': 0.33; 'problem': 0.33; 'foo': 0.33; 'traditional': 0.33; 'file': 0.34; 'handle': 0.34; 'skip:d 20': 0.34; 'that,': 0.34; 'remote': 0.35; 'skip:i 20': 0.36; 'possible': 0.36; 'modules': 0.36; 'urls': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'itself': 0.38; 'represent': 0.38; 'data': 0.39; 'build': 0.40; 'well.': 0.40; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'ever': 0.60; 'your': 0.60; 'provide': 0.61; 'per': 0.62; 'providing': 0.62; 'more': 0.63; 'safe': 0.63; 'dont': 0.64; 'past.': 0.66; 'services.': 0.72; 'facilities': 0.72; 'authentic': 0.84
X-Authority-Analysis v=2.1 cv=av94c3tV c=1 sm=1 tr=0 a=g3mLq75WYuDrh3Lt0JSDww==:117 a=g3mLq75WYuDrh3Lt0JSDww==:17 a=QC7fh9NfAAAA:8 a=5pFAO2ZBLFIA:10 a=8nJEP1OIZ-IA:10 a=ff-B7xzCdYMA:10 a=ZRRpdE0JF9pLNxAeHIMA:9 a=wPNLvfGTeEIA:10
X-Spam-Checker-Version SpamAssassin 3.4.0 (2014-02-07) on mail.activenetwerx.com
X-Spam-Level *
X-Spam-Status No, score=1.3 required=5.0 tests=RDNS_NONE autolearn=no autolearn_force=no version=3.4.0
From "Joseph L. Casale" <jcasale@activenetwerx.com>
To "Sven R. Kunze" <srkunze@mail.de>, "python-list@python.org" <python-list@python.org>
Subject Re: Writing a module to abstract a REST api
Thread-Topic Writing a module to abstract a REST api
Thread-Index AQHQ8VdKzAS7nkl7nU2AayZu81Yu155BmmuAgADNE1U=
Date Fri, 18 Sep 2015 15:28:28 +0000
References <55FB2A8F.9050501@mail.de>
In-Reply-To <55FB2A8F.9050501@mail.de>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-ms-exchange-transport-fromentityheader Hosted
x-originating-ip [72.29.233.193]
Content-Type text/plain; charset="iso-8859-1"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-CMAE-Envelope MS4wfJd/BkQwYsPbrrk+zDSgclJGNt+w+HPQLIBMaBY9DCjn9c2MI2qlsk39c0SJt0ywhEkGp5+5AIrntnX3aVQKJ+yk9picsNQvql/N+TiEk+nxcfw+AmP+JsoxHcUvmEzNyc3bYcnlujzMgdtimTl4bd5rtGbBGOQv5aU0qcO3mKTjjqjg9gWkpNu7TtfwlpPSIg==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.35.1442590114.16376.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1442590114 news.xs4all.nl 23840 [2001:888:2000:d::a6]:57868
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:96825

Show key headers only | View raw


> Well, I would be interested in seeing such a module as well.
> 
> Most modules and frameworks, I know, providing REST and interacting with
> REST are more like traditional SOAP-like web services. You got your
> functions which have a 1-to-1 correspondence with some resource URLs and
> that's it.
> 
> Actually REST is far more flexible than that, thus I still would love to
> see an authentic REST module.

So a design pattern I use often is to create Python objects to represent
objects returned from what ever api I am abstracting. For example I
might create named tuples for static data I dont intend to change or
for an object I can both query for and create, I might build a class to
represent it.

The problem now comes from the following:

# foo now contains a handle to the remote api.
foo = InstanceOfApiWrapper()

# queues is a container of Queue classes.
queues = foo.get_queues()

queue = queues[0]
queue.delete()

In this case its possible for foo (InstanceOfApiWrapper) to inject a reference
to itself so the delete() can actually make the call.

# I want to create a queue from scratch...
disparate_queue = Queue(x, y, z)
# Now what happens? No handle to an api?
disparate_queue.delete()

An alternative is:
foo.delete_queue(disparate_queue)

That's not a pattern I prefer, what facilities in Python provide for a workaround
here?

One option is to put everything in one module and use globals. If the handle is
initialized it'll just work.

Problem with that is its not thread safe (without work) and I subscribe to
one object per file (bloody hard with Python's import/load procedure.

This is a design pattern I have struggled with in the past.
jlc

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Writing a module to abstract a REST api "Joseph L. Casale" <jcasale@activenetwerx.com> - 2015-09-18 15:28 +0000

csiph-web