1. Home
  2. /
  3. Tornado Typing Test
  4. /
  5. Simple Counter API

Simple Counter API - Tornado Typing CST Test

Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.

Simple Counter API — Tornado Code

Demonstrates a simple Tornado REST API with a counter using async handlers and in-memory state.

import tornado.ioloop
import tornado.web

count = 0

class CounterHandler(tornado.web.RequestHandler):
	async def get(self):
		self.write({'count': count})

class IncrementHandler(tornado.web.RequestHandler):
	async def post(self):
		global count
		count += 1
		self.write({'count': count})

class DecrementHandler(tornado.web.RequestHandler):
	async def post(self):
		global count
		count -= 1
		self.write({'count': count})

class ResetHandler(tornado.web.RequestHandler):
	async def post(self):
		global count
		count = 0
		self.write({'count': count})

app = tornado.web.Application([
	(r'/counter', CounterHandler),
	(r'/counter/increment', IncrementHandler),
	(r'/counter/decrement', DecrementHandler),
	(r'/counter/reset', ResetHandler)
])

if __name__ == '__main__':
	app.listen(8888)
	tornado.ioloop.IOLoop.current().start()

Tornado Language Guide

Tornado is a Python web framework and asynchronous networking library, designed for handling thousands of simultaneous connections. It excels at real-time web services and long-lived network connections.

Primary Use Cases

  • ▸Real-time chat applications
  • ▸WebSocket-based dashboards
  • ▸High-concurrency APIs and services
  • ▸Long-polling or streaming data endpoints
  • ▸IoT backends and notification services

Notable Features

  • ▸Asynchronous, non-blocking I/O
  • ▸Integrated web framework and networking library
  • ▸Native WebSocket support
  • ▸High concurrency for thousands of clients
  • ▸Flexible request handling with coroutines

Origin & Creator

Tornado was created by FriendFeed engineers (Brett Slatkin, David Cournapeau, and others) in 2009, later maintained by Facebook and the open-source community.

Industrial Note

Tornado is preferred for real-time web services, WebSocket servers, and high-concurrency applications where traditional WSGI frameworks may struggle.

Quick Explain

  • ▸Tornado uses a non-blocking, single-threaded event loop for handling concurrent connections efficiently.
  • ▸It combines a web framework with a scalable networking library, suitable for real-time apps.
  • ▸Supports WebSockets, long polling, and streaming responses natively.
  • ▸Provides asynchronous request handling using Python's `asyncio` or Tornado's own I/O loop.
  • ▸Commonly used for chat applications, live dashboards, and APIs requiring high concurrency.

Core Features

  • ▸RequestHandler classes for defining endpoints
  • ▸Async I/O via `async def` or `gen.coroutine`
  • ▸Built-in support for WebSockets
  • ▸Streaming responses and long-lived connections
  • ▸Routing via `tornado.web.Application`

Learning Path

  • ▸Learn Python 3 basics
  • ▸Understand async/await and coroutines
  • ▸Create Tornado RequestHandler classes
  • ▸Implement async APIs and WebSockets
  • ▸Deploy high-concurrency Tornado apps

Practical Examples

  • ▸Real-time chat server
  • ▸Streaming stock price dashboard
  • ▸Notification push service
  • ▸Async CRUD API for IoT devices
  • ▸Live collaboration platform backend

Comparisons

  • ▸Tornado vs Flask: Tornado supports async and WebSockets, Flask is WSGI-based
  • ▸Tornado vs Django: Tornado is async and lightweight, Django is feature-rich
  • ▸Tornado vs FastAPI: Both async, Tornado includes low-level I/O, FastAPI uses Starlette for async web
  • ▸Tornado vs Node.js frameworks: Tornado is Python-based, async event-loop similar to Node.js
  • ▸Tornado vs Koa.js: Koa is Node.js minimal async, Tornado is Python async with networking library

Strengths

  • ▸Handles large numbers of simultaneous connections efficiently
  • ▸Real-time and streaming-friendly
  • ▸Async/await syntax support
  • ▸Lightweight and extensible
  • ▸Good for low-latency applications

Limitations

  • ▸Less suited for CPU-bound workloads
  • ▸Smaller ecosystem compared to Django or Flask
  • ▸Requires understanding of asynchronous programming
  • ▸Manual setup for templating, authentication, and forms
  • ▸Not ideal for simple static websites

When NOT to Use

  • ▸CPU-bound applications
  • ▸Simple websites without concurrency needs
  • ▸Projects needing a large ecosystem of pre-built modules
  • ▸Teams unfamiliar with async programming
  • ▸Applications requiring complex ORMs or admin panels

Cheat Sheet

  • ▸import tornado.web, tornado.ioloop -> import modules
  • ▸class MainHandler(tornado.web.RequestHandler) -> define handler
  • ▸async def get(self): -> async GET method
  • ▸app = tornado.web.Application([...]) -> create app
  • ▸app.listen(port); tornado.ioloop.IOLoop.current().start() -> start server

FAQ

  • ▸Is Tornado free?
  • ▸Yes - open-source under the Apache 2.0 license.
  • ▸Does Tornado support async/await?
  • ▸Yes - supports Python's async/await syntax.
  • ▸Is Tornado suitable for production?
  • ▸Yes - especially for real-time and high-concurrency apps.
  • ▸Does Tornado include WebSocket support?
  • ▸Yes - built-in WebSocketHandler class.
  • ▸Can Tornado scale horizontally?
  • ▸Yes - with multiple processes and load balancers.

30-Day Skill Plan

  • ▸Week 1: Python 3 and asyncio fundamentals
  • ▸Week 2: Tornado basics and routing
  • ▸Week 3: Async request handling and IOLoop
  • ▸Week 4: WebSockets and streaming endpoints
  • ▸Week 5: Deployment and performance tuning

Final Summary

  • ▸Tornado is an asynchronous Python web framework and networking library.
  • ▸Designed for high-concurrency, real-time web services.
  • ▸Supports HTTP, WebSockets, and streaming responses.
  • ▸Flexible, lightweight, and event-loop-based architecture.
  • ▸Ideal for APIs, chat servers, live dashboards, and IoT backends.

Project Structure

  • ▸app.py - main server file
  • ▸handlers/ - RequestHandler classes
  • ▸templates/ - HTML templates if used
  • ▸static/ - static files (CSS, JS, images)
  • ▸utils/ - helper modules and services

Monetization

  • ▸Backend for SaaS real-time platforms
  • ▸Live streaming and dashboards
  • ▸IoT notification services
  • ▸API-as-a-service solutions
  • ▸Microservices for small-to-medium businesses

Productivity Tips

  • ▸Use async handlers to avoid blocking
  • ▸Compose small reusable handler classes
  • ▸Monitor logs to detect slow operations
  • ▸Automate tests and deployments
  • ▸Integrate with async libraries for DB and caching

Basic Concepts

  • ▸IOLoop - core event loop
  • ▸Application - main server object
  • ▸RequestHandler - class to handle HTTP requests
  • ▸WebSocketHandler - class for WebSocket connections
  • ▸Async coroutines - for non-blocking operations

Official Docs

  • ▸https://www.tornadoweb.org/
  • ▸https://github.com/tornadoweb/tornado

More Tornado Typing Exercises

Tornado Hello World APITornado JSON EchoTornado Query Parameter ExampleTornado Route Parameter ExampleTornado Middleware LoggingTornado Async Delay ExampleTornado 404 ExampleTornado Combined Routes Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher