Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7623591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:44:42+00:00 2026-05-31T04:44:42+00:00

I’m working on a REST client library, and recently started working on adding support

  • 0

I’m working on a REST client library, and recently started working on adding support for sending batch messages.

However, I don’t like the current design. It requires you to maintain large Client and RequestMessage classes with identical method signatures.

I am looking for a way to consolidate the two classes.

The original Client class’s methods contained all the code needed to prepare and send the request:

class Client(object):

   def __init__(self, config):
       self.request = Request(config, "application/json")

   def create_vertex(self, data):
       path = "vertices"
       params = remove_null_values(data)
       self.request.post(path, params)

To add support for batch messages, I pulled out the guts of the code inside the each Client method, and put it into a separate RequestMessage class so that you can add the messages to the batch without sending it, until you’re ready:

class Client(object):

   def __init__(self, config):
       self.request = Request(config, "application/json")
       self.message = RequestMessage(config)

   def create_vertex(self, data):
       message = self.message.create_vertex(data)
       return self.request.send(message)

   # ...more REST client methods...

   def batch(self, messages):
       path = "batch" 
       params = messages
       return self.request.post(path, params)       

class RequestMessage(object):

   def __init__(self, config):
       self.config = config

   def create_vertex(self, data):
       path = "vertices"
       params = remove_null_values(data)
       return POST, path, params

  # ...more REST client methods...

But I don’t like the design because now you have to maintain the Client and RequestMessage class — two large classes with identical signatures.

Here’s what the Batch class looks like:

class Batch(object):

   def __init__(self, client):
       self.client = client
       self.messages = []

   def add(self, message):
       self.messages.append(message)

   def send(self):
       return self.client.batch(self.messages)

Here’s example usage for creating a vertex on the server:

>>> client = Client(config)
>>> vertex = client.create_vertex({'name':'James'})

Here’s example usage for creating a batch of vertices on the server:

>>> message1 = client.message.create_vertex({'name':'James'})
>>> message2 = client.message.create_vertex({'name':'Julie'})
>>> batch = Batch(client)
>>> batch.add(message1)
>>> batch.add(message2)
>>> batch.send()

Batch is used less frequently than Client so I want to make the normal Client interface easiest to use.

Here’s one idea, but I’m not quite sure how to achieve it or if something else would be better:

   >>> vertex = client.create_vertex(data)
   >>> message = client.create_vertex(data).message()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:44:43+00:00Added an answer on May 31, 2026 at 4:44 am

    My personal preference is an API like:

    client.create_vertex({'name':'James'}) # single
    client.create_vertex([{'name':'James'}, {'name':'Julie'}]) # batch
    

    That way you use the exact same function, you’re just giving it more data. Typical usage would probably look more like:

    batch = []
    batch.append({'name':'James'})
    batch.append({'name':'Julie'})
    client.create_vertex(batch)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.