api-design

REST api design to retrieve summary information

I have a scenario in which I have REST API which manages a Resource which we will call Group. A Group is similar in concept to a discussion forum in Google Groups. Now I have two GET access method which I believe needs separate representations. The 1st GET access method retrieves the minimal amount of information about a Group. Given ...

Using HTTP Vary header to decide on a strategy to process a request

I have a specific REST endpoint that creates a topic in a forum; but I want to apply different strategies when processing the request. e.g. If client A makes the call, perform moderation. if client B makes the call, do something else. The easiest would be to add a query param for differentiation: POST /resource?from=xyz Another brill...

Does it make sense to use internal anchors for filtering a REST API's representation ?

As a follow up to my previous question about REST URIs for retrieving statistical information for a web forum Resource, I want to know if it is possible to use the internal anchors as filter hints. See example below: a) Get all statistics: GET /group/5t7yu8i9io0op/stat { group_id: "5t7yu8i9io0op", top_ranking_users: { [ ...

Best practices and guidelines for designing an API

What are some guidelines and best practices that I can adhere to while designing an API? At the bare minimum, I know that an API should be easy to use and flexible. Unfortunately those terms can be rather subjective, so I was looking for some concrete guidelines relating to good API design. ...

Using implicit conversion as a substitute for multiple inheritance in .NET

I have a situation where I would like to have objects of a certain type be able to be used as two different types. If one of the "base" types was an interface this wouldn't be an issue, but in my case it is preferable that they both be concrete types. I am considering adding copies of the methods and properties of one of the base types...

ViewStateMode in ASP.NET 4.0 - backward compatibility?

Was the new ViewStateMode property introduced to avoid breaking the existing EnableViewState? Does setting EnableViewState = false at the page level causee the ViewStateMode setting to be ignored? PS: What is CW in stackoverflow? ...

Multiple operations depending on the type of the object passed

Assuming I create a method which is passed an object and that method would perform an action depending on the object passed. How should I identify the object? I thought of using the class name to identify the object, but that may be impractical since I could easily change the class name of objects, and generate headaches during future d...

How to do inclusive range queries when only half-open range is supported (ala SortedMap.subMap)

On SortedMap.subMap This is the API for SortedMap<K,V>.subMap: SortedMap<K,V> subMap(K fromKey, K toKey) : Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. This inclusive lower bound, exclusive upper bound combo ("half-open range") is something that is prevalent in Java, and...

Books about Javascript API design best practices

Hi, Anyone can suggest good books about Javascript API design good practices? What are the common practices developed by Google, Twitter, Facebook in their APIs. Code organization, request control etc. ...

Tips on designing a .NET API for future use with F#

I'm in the process of designing a .NET API to allow developers to create RoboCup agents for the 3D simulated soccer league. I'm pretty happy with how the API work with C# code, however I would like to use this project to improve my F# skill (which is currently based on reading rather than practice). So I would like to ask what kinds of...

Why does Iterables.find() in Guava throw NoSuchElementException, instead of returning null?

I love Google Guava and use it a lot, but there is one method I always find me writing.. public static <T> T tryFind(Iterable<T> iterable, Predicate<T> predicate){ for(T t : iterable){ if(predicate.apply(t)){ return t; } } return null; } To me this seems to be a very useful addition to...

Why does int num = Integer.getInteger("123") throw NullPointerException?

hi, the following code throws NPE for me: int num = Integer.getInteger("123"); is my compiler invoking getInteger on null since it's static? that doesn't make any sense! can someone explain what's happening? thanks. ...

Platform Independent Tool for Creating API Documentation / Proposal

What tools exist for developing platform indepedent API Documentation? I'm in the process of designing a proposed API, and want to write documentation in a structured and easily editable way. A lot of the answers I've seen have basically been "Use built in language specific documentation tools", but since I'm designing the API from a 't...

Why does String.valueOf(null) throw a NullPointerException?

Hi, according to the documentation, the method String.valueOf(Object obj) returns: if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned. But how come when I try do this: System.out.println("String.valueOf(null) = " + String.valueOf(null)); it throws NPE instead? (try it your...

What design is better: universal builder or several concrete methods?

I need to create an email-notification service (as a part of a bigger project). It will be used to send several types of notification messages which are based on html-templates. I can design it in two ways: The first way is based on the builder pattern. It's universal (as I think) and can handle all necessary cases. But it's not ve...

API design: is "fault tolerance" a good thing?

I've consolidated many of the useful answers and came up with my own answer below For example, I am writing a an API Foo which needs explicit initialization and termination. (Should be language agnostic but I'm using C++ here) class Foo { public: static void InitLibrary(int someMagicInputRequiredAtRuntime); static void TermLi...

Should ScheduledExecutorService.scheduleAt* methods re-schedule tasks if the task throws RuntimeException/Error?

The other day I was implementing an important service in my application, that should continue to run no matter what. So I used the following construct: ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(); //If the thread dies, another will take over ses.scheduleAtFixedRate(importantPeriodicTask, 1, 1, TimeUnit.N...

Securing third-party JavaScript code

I'm building a system that allows multiple third-party plugins/gadgets conforming to the system's API to be run simultaneously on the page. What is the best practice of securing or isolating these plugins from one another, aside from running them in separate iframes? Should I design the API so that data fields of these plugins are priv...

Where should we document our public API?

I'm looking for a wiki like software where we can publish our public api documentation. I have found many people to use MediaWiki but this does not seem to be the most elegant way of doing it. I would love to have a place where we can easily define the APIs specs and have it in an easy to read format. I like how twitter did their api d...

Retrofitting void methods to return its argument to facilitate fluency: breaking change?

"API design is like sex: make one mistake and support it for the rest of your life" (Josh Bloch on twitter) There are many design mistakes in the Java library. Stack extends Vector (discussion), and we can't fix that without causing breakage. We can try to deprecate Integer.getInteger (discussion), but it's probably going to stay ar...