{"id":9992,"library":"nsj-rest-lib2","title":"NSJ REST Lib2","description":"nsj-rest-lib2 is a Python library designed to enable the distribution of dynamic REST API routes. These routes are configured declaratively using JSON-based Endpoint Definition Language (EDL) files. It leverages Flask and Flask-RESTful to integrate these dynamic routes into an existing Flask application. The current version is 0.0.41, and it undergoes frequent patch updates, indicating active development.","status":"active","version":"0.0.41","language":"python","source_language":"en","source_url":"https://github.com/Nasajon/nsj_rest_lib2","tags":["REST API","dynamic routes","Flask","declarative","JSON","EDL"],"install":[{"cmd":"pip install nsj-rest-lib2","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Required for processing Endpoint Definition Language (EDL) configurations.","package":"nsj-processor"},{"reason":"Core web framework for handling HTTP requests.","package":"Flask"},{"reason":"Required for Cross-Origin Resource Sharing (CORS) support.","package":"Flask-Cors"},{"reason":"Extension for quickly building REST APIs with Flask.","package":"Flask-RESTful"},{"reason":"Used for data validation of models and configurations.","package":"pydantic"},{"reason":"Another internal Nasajon library providing web utilities.","package":"nsj-web-tools"}],"imports":[{"wrong":"from nsj_rest_lib2 import create_dynamic_rest_api_endpoint_from_json","symbol":"create_dynamic_rest_api_endpoint_from_json","correct":"from nsj_rest_lib2 import create_dynamic_rest_api_endpoint_from_json"}],"quickstart":{"code":"import sys\nfrom types import ModuleType\nfrom flask import Flask\nfrom nsj_rest_lib2.register import register_route\nfrom nsj_rest_lib2.util import create_dynamic_rest_api_endpoint_from_json\nimport os\n\n# --- Step 1: Define your endpoint logic ---\n# In a real application, 'my_app_endpoints' would be a real .py file\n# and MyEndpointClass would be a class defined within it.\nclass MyEndpointClass:\n    def my_dynamic_method(self):\n        \"\"\"A simple method to be called by the dynamic route.\"\"\"\n        return {\"message\": \"Hello from nsj-rest-lib2 dynamic endpoint!\"}, 200\n\n# Dynamically add this class to a mock module in sys.modules\n# This allows create_dynamic_rest_api_endpoint_from_json to find it\n# without needing an actual file on disk for this quickstart example.\nmock_module_name = 'my_app_endpoints'\nif mock_module_name not in sys.modules:\n    sys.modules[mock_module_name] = ModuleType(mock_module_name)\nsetattr(sys.modules[mock_module_name], 'MyEndpointClass', MyEndpointClass)\n\n\n# --- Step 2: Initialize Flask application ---\napp = Flask(__name__)\napp.secret_key = os.environ.get('FLASK_SECRET_KEY', 'a_super_secret_key_for_dev') # Required for some Flask extensions\n\n# --- Step 3: Define the declarative route configuration (EDL) ---\nroute_config_json = {\n    \"uri\": \"/api/v1/dynamic-resource\",\n    \"http_method\": \"GET\",\n    \"endpoint_module\": mock_module_name, # References the mock module\n    \"endpoint_class_name\": \"MyEndpointClass\", # Class containing the method\n    \"endpoint_method_name\": \"my_dynamic_method\", # Method to be called\n    \"request_body_model_name\": None,\n    \"response_body_model_name\": None,\n    \"query_string_model_name\": None,\n    \"path_params_model_name\": None,\n    \"header_params_model_name\": None,\n    \"jwt_roles\": [],\n    \"jwt_allowed\": False,\n    \"jwt_required\": False\n}\n\n# --- Step 4: Create and register the dynamic endpoint ---\ndynamic_endpoint = create_dynamic_rest_api_endpoint_from_json(route_config_json)\nregister_route(app, dynamic_endpoint)\n\n# --- Step 5: Run the Flask application (for demonstration) ---\n# In a production environment, use a WSGI server like Gunicorn or Waitress.\nif __name__ == '__main__':\n    print(\"\\nFlask application running at http://127.0.0.1:5000\")\n    print(\"Test with: curl http://127.0.0.1:5000/api/v1/dynamic-resource\")\n    app.run(debug=True, port=5000)\n","lang":"python","description":"This quickstart demonstrates how to define an Endpoint Definition Language (EDL) configuration in JSON, use `create_dynamic_rest_api_endpoint_from_json` to create a dynamic endpoint object, and then `register_route` to add it to a Flask application. It includes a minimal Flask app and a dynamically created mock module to make the example runnable and testable. To run, save as a Python file and execute `python your_file.py`. Then, access `http://127.0.0.1:5000/api/v1/dynamic-resource` in your browser or with `curl`."},"warnings":[{"fix":"Pin your dependency to a specific patch version (`nsj-rest-lib2==0.0.41`) and thoroughly test after any upgrade. Consult the GitHub repository for the latest EDL schema documentation.","message":"The library is in version `0.0.x`, indicating it's in early development. API interfaces, especially the structure of the declarative JSON (EDL), may change frequently and without major version bumps. Always review release notes when upgrading.","severity":"breaking","affected_versions":"All `0.0.x` versions"},{"fix":"Ensure the module is discoverable on `sys.path`, and the class/method names precisely match their definitions, including case sensitivity. Verify that the module can be `importlib.import_module`'d.","message":"Incorrectly specified `endpoint_module`, `endpoint_class_name`, or `endpoint_method_name` in the EDL JSON will lead to runtime errors when the dynamic route is accessed, as the library won't be able to locate and invoke the specified Python code.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Carefully review the required fields and their types according to the library's internal `DynamicRouteConfigDTO` or official examples. Ensure all mandatory fields like `uri`, `http_method`, `endpoint_module`, `endpoint_class_name`, and `endpoint_method_name` are present and correctly formatted.","message":"The declarative JSON (EDL) for defining routes is validated using Pydantic. Any deviation from the expected schema, such as missing required fields or incorrect data types, will result in `pydantic.error_wrappers.ValidationError` during endpoint creation.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.0.41':57 'activ':65 'api':20,68 'applic':52 'base':30 'configur':25 'current':54 'declar':26,72 'definit':32 'design':12 'develop':66 'distribut':16 'dynam':18,46,69 'edl':34,74 'enabl':14 'endpoint':31 'exist':50 'file':35 'flask':38,41,51,71 'flask-rest':40 'frequent':61 'indic':64 'integr':44 'json':29,73 'json-bas':28 'languag':33 'leverag':37 'lib2':3,7 'librari':11 'nsj':1,5 'nsj-rest-lib2':4 'patch':62 'python':10 'rest':2,6,19,42,67 'rout':21,23,47,70 'undergo':60 'updat':63 'use':27 'version':55","created_at":"2026-04-17T01:21:48.179354+00:00","updated_at":"2026-04-17T01:21:48.179354+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nImportError: cannot import name 'create_dynamic_rest_api_endpoint_from_json' from 'nsj_rest_lib2' (/tmp/tmpkmi8pe7n/venv/lib/python3.12/site-packages/nsj_rest_lib2/__init__.py)"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.0.41","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Nasajon/nsj_rest_lib2","docs":null,"changelog":null,"pypi":"https://pypi.org/project/nsj-rest-lib2/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}