Time for a JSON library.
Separated processing a request from receiving it.
We now appear to handle factoring multiple numbers, although raising an exception could get in the way.
Made use of JSON clearer and easier to add options.
Clarified the various APIs.
If we can process the prime factors of a single number, then we can assemble the results from many of them into a suitable response.
Extracted some context-independent code into its own method.
Moved semantic checking closer to where it belongs.
Clarified contracts. Avoided stack traces.
Formatted code more consistently.