Mocking Server Data to Mock UI

245 views
Skip to first unread message

Matt Hughes

unread,
Dec 11, 2013, 6:07:21 PM12/11/13
to ang...@googlegroups.com
Does anyone have any good strategies for developing fake data to run your app against?  I'm currently laying out some screens with server resources in mind but they aren't developed yet.  Ideally, I'd like to be able to run my app with a bunch of fake data generated in JS.  My thoughts are if I hit my app with a ?dummyData=true, I would somehow switch to using httpBackend and have code that would generate fake data for each resource.

Has anyone done anything like this?  I currently hard-code the fake data generation in my controllers and then when the backend is ready, I switch over to the real thing. 

Alon Nisser

unread,
Dec 12, 2013, 6:46:22 AM12/12/13
to ang...@googlegroups.com
I've been in hard-code fake data land and It's not pretty. I use a slightly different solution for this:

1. use the api address as a constant that services that need it can inject
2. use grunt ngconstant to allow me to switch between configurations easily (mock, staging, production, whatever) - in this config module I set the api address
3. use Dyson which is a simple and great fake api server (supporting get, post, delete, put, dynamic template generation etc and also just returning hardcoded JSON)  and. where I setup endpoints ( the docs are good) and configure the dyson api as one of the config options (like API_ADDRESS= http://localhost:8088/. and configure dyson to listen to that port
4. enjoy

Also notice the the dyson #dev version (you'll need to npm install -g from github with the branch name) supports proxying to the real api (and I know, because I asked for the feature and currently beta testing it :) )
if you setup a dyson.json with the proxying data - so If you remove (or comment..) a mock endpoint from dyson config you'll have the request proxied to your real api. that allows me to remove fake endpoint as they are being implemented by the backend guys,

Hope that helps!

Mark Volkmann

unread,
Dec 12, 2013, 9:48:15 AM12/12/13
to ang...@googlegroups.com
I have a Node script that runs an HTTP server using Express. It looks for certain HTTP requests and returns fake data. For any requests it isn't looking for, it forwards the request onto our real server which happens to be Tomcat and hits a database to get data.

This has worked out great. When the real back-end is ready I just need to remove a few lines of code from the Node script. I'd be happy to share that script if anyone is interested.


On Wed, Dec 11, 2013 at 5:07 PM, Matt Hughes <hughe...@gmail.com> wrote:
Does anyone have any good strategies for developing fake data to run your app against?  I'm currently laying out some screens with server resources in mind but they aren't developed yet.  Ideally, I'd like to be able to run my app with a bunch of fake data generated in JS.  My thoughts are if I hit my app with a ?dummyData=true, I would somehow switch to using httpBackend and have code that would generate fake data for each resource.

Has anyone done anything like this?  I currently hard-code the fake data generation in my controllers and then when the backend is ready, I switch over to the real thing. 

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.



--
R. Mark Volkmann
Object Computing, Inc.

Matt Hughes

unread,
Dec 18, 2013, 2:11:27 PM12/18/13
to ang...@googlegroups.com
I’d definitely like to see.  Gist?

-- 
Matt Hughes
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/ji6qIUX04FY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages