API factory for a realtime chat site
James Heald said:


  I was told I'm using factories wrong, but I'm not so sure.


The people telling you that are technically correct. A "factory" is an object or method whose sole purpose for existence is to create other objects. Factories are generally used when you want to create a concrete sub type, but return either an interface or a common parent type.

From Wikipedia: Factory (object-oriented programming)


  In class-based programming, a factory is an abstraction of a constructor of a class, while in prototype-based programming a factory is an abstraction of a prototype object. A constructor is concrete in that it creates objects as instances of a single class, and by a specified process (class instantiation), while a factory can create objects by instantiating various classes, or by using other allocation schemes such as an object pool. A prototype object is concrete in that it is used to create objects by being cloned, while a factory can create objects by cloning various prototypes, or by other allocation schemes.


Your apiFactory object is technically returning "new" objects, but since it is making web service calls, you've actually created a "service object".

More info: AngularJS Services.

Really the problem is the name "apiFactory" because the apiFactory variable itself is not a factory. It is a service. A more appropriate name might be ChatService.

The function that returns apiFactory is actually the factory, whereas apiFactory is actually the service.