### in urls.py from django.conf.urls.defaults import * from bench.songs.views import Song, All urlpatterns = patterns('', (r'^$', All()), (r'^song/(?P\d+)/', Song()), ) ### in songs/views.py from django.http import HttpResponse from collections import defaultdict ## RestView from http://www.djangosnippets.org/snippets/1071/ from bench.rest import RestView counts = defaultdict(int) class All(RestView): def GET(self, request, *args): res = ','.join(['%s=%s' % (k, v) for k, v in counts.iteritems()]) return HttpResponse(res, mimetype='text/plain') def DELETE(self, request): counts = defaultdict(int) return HttpResponse('OK', mimetype='text/plain') class Song(RestView): def GET(self, request, id): return HttpResponse(str(counts[id]), mimetype='text/plain') def POST(self, request, id): counts[id] += 1 return HttpResponse(str(counts[id]), mimetype='text/plain')