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 6780613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:31:35+00:00 2026-05-26T16:31:35+00:00

I have a about 20 different services which I have to send requests to

  • 0

I have a about 20 different services which I have to send requests to which require a slightly different set of headers.

The bad legacy code is something like this,

row = db.query_for_service()

if row.type == 'foo1'
   // add common headers to request
   // add foo1 specific headers 1
   // add foo1 specific header 2
   // add foo1 specific header 3
else if row.type == 'foo2'
   // add common headers to request
   // add foo2 specific header 1
...
...
...
else if row.type == foo20
   // add common headers to request
   // add foo20 specific header 1
   // add foo20 specific header 2 
   // ...

send_request()

What is the best way to refactor this? I have considered some patterns that may work here (strategy, builder) but I am not too sure.

I am currently learning both Java and Python and I would to get thoughts on how the solutions would differ in the two languages

  • 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-26T16:31:36+00:00Added an answer on May 26, 2026 at 4:31 pm

    Personally, what I would do is something along these lines.

    #Put this in the initialisation 
    Map foos<row.type,String> = new Map<row.type, String>()
    #Populate the map 
    map.set('a') = 'headerA specific params x=1'
    map.set('b') = 'headerB specific params x=2'
    map.set('c') = 'headerC specific params y=3'
    map.set ...
    
    Map bars<String,String> = new Map<String,String()
    bars.set('fooA') = 'a,b'
    bars.set('fooB') = 'a,c'
    String commonheader = "HTTP/1.1"
    
    
    #This would be in a method    
    row = db.query_for_service()
    String output_header += commonheader
    for i in bars.get(fooN).split(','):
        output_header += foos.get(i)
    send_request()
    

    In sort of pseudo java/python. The map would be pre-filled with everything you need, then just pick out what you want and attach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very bad feeling about using lock in my code but now
I have two related questions about Web services: (1) I'm currently writing a set
At my house I have about 10 computers all different processors and speeds (all
Recently I have read a lot about different NoSQL databases and how they are
I have a scene in my WPF project with about 2000 different user controls:
I have implemented an IHttpAsyncHandler. I am making about 5 different AJAX calls from
I have a bit of a situation. I've consumed about fourty-eleven different tutorials/books/videos on
Do I have to put every file in a different folder? like: about-us/about-us.php profile/profile.php
I'm thinking about how to do this, but I have several different shapes of
I have a web app that I'm building. It uses 3 different web services

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.