GithubHelp home page GithubHelp logo

ederjc / micropython-nanoweb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hugokernel/micropython-nanoweb

0.0 0.0 0.0 38 KB

Full async Micropython web server with small memory footprint.

License: MIT License

JavaScript 8.85% Python 80.29% CSS 0.54% HTML 10.32%

micropython-nanoweb's Introduction

Nanoweb

Nanoweb is a full asynchronous web server for micropython created in order to benefit from a correct ratio between memory size and features.

It is thus able to run on an ESP8266, ESP32, Raspberry Pico, etc...

Features

  • Completely asynchronous
  • Declaration of routes via a dictionary or directly by decorator
  • Management of static files (see assets_extensions)
  • Callbacks functions when a new query or an error occurs
  • Extraction of HTML headers
  • User code dense and conci
  • Routing wildcards

Installation

You just have to copy the nanoweb.py file on the target (ESP32, Nano, etc...).

Use

See the example.py file for an advanced example where you will be able to:

  • Make a JSON response
  • Use pages protected with credentials
  • Upload file
  • Use DELETE method
  • Read POST data

And this is a simpler example:

import uasyncio
from nanoweb import Nanoweb

naw = Nanoweb()

async def api_status(request):
    """API status endpoint"""
    await request.write("HTTP/1.1 200 OK\r\n")
    await request.write("Content-Type: application/json\r\n\r\n")
    await request.write('{"status": "running"}')

# You can declare route from the Nanoweb routes dict...
naw.routes = {
    '/api/status': api_status,
}

# ... or declare route directly from the Nanoweb route decorator
@naw.route("/ping")
async def ping(request):
    await request.write("HTTP/1.1 200 OK\r\n\r\n")
    await request.write("pong")

loop = uasyncio.get_event_loop()
loop.create_task(naw.run())
loop.run_forever()

Contribute

micropython-nanoweb's People

Contributors

hugokernel avatar puhitaku avatar ederjc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.