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

  • Home
  • SEARCH
  • 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 6988885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:08:22+00:00 2026-05-27T19:08:22+00:00

I am trying to make a library that accesses an online RESTful API. The

  • 0

I am trying to make a library that accesses an online RESTful API. The API has defined a list of implemented methods, and allowed parameters for each method and (in some cases) allowed values for given parameters. I was thinking I would like to ensure that (A) only implemented methods can be called; (B) only allowed parameters can be defined for a given method; and (C) where only certain values are allowed for a given parameter, only allow those values.

(A) is relatively easy just using an enum “Method”:

public enum Method {
    getObjectById,
    getObjectBySearch, 
    ...
}

for (B) I was thinking each instance of Method then needs to have it’s own enum of allowed parameters and for (C) some parameters, an enum of allowed values, sort of like (I’m sorry if this makes anybody cringe):

NOTE: THE FOLLOWING CODE IS NOT VALID JAVA; IT IS ONLY HERE AS A CONCEPTUAL EXAMPLE.

public enum Method {
    getObjectById () {
        enum Parameter {
            objectId;
    },
    getObjectBySearch () {
        enum Parameter {
            query,
            queryType () {
                enum Type { type1, type2 }
            }
        }
    }
}

Obviously, local enumerations are not allowed in Java, so this can’t be done; and I imagine there are more elegant ways to achieve my end goal, but I’ve been out of practice for over 5 years, so I’m struggling to find them.

Or perhaps I’m overthinking this and trying to achieve this kind of type safety in parameters and values of my request is really bad practice (again I’m not very experienced) – if this is the case, I would appreciate an explanation as to why it is bad practice.

Thanks,
– Igor

  • 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-27T19:08:23+00:00Added an answer on May 27, 2026 at 7:08 pm

    Why don’t you just wrap every method call inside a service object which validates its arguments?

    public class Service {
        public SomeObject getObjectById(String objectId) {
            if (isNotValidObjectId(objectId) {
                throw new IllegalArgumentException("objectId is invalid");
            }
            // TODO call the appropriate method
        }
    
        public SomeObject getObjectBySearch(String query, QueryType queryType) {
            if (isNotValidQuery(query) {
                throw new IllegalArgumentException("query is invalid");
            }
            if (queryType == null) {
                throw new IllegalArgumentException("queryType is mandatory");
            }
            // TODO call the appropriate method
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make an API library for our web services, and I'm wondering
I'm trying to make a library file. The .cpp file has some conditional compiled
I'm trying to make a watertight interface to a library that I'm designing. The
I'm trying to make a python binding for the this library: http://code.google.com/p/hosterslib/ . I'm
Trying to make a make generic select control that I can dynamically add elements
Trying to make a custom :confirm message for a rails form that returns data
I'm trying to make a set of custom tags that encapsulate form elements (markup
Im trying to make a small app in c++ that saves midifiles with this
I am trying to make an iPhone-app that does the Monte Carlo simulation on
I've been trying to make some applications which all rely on the same library,

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.