Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Routing and Controllers #27

Merged
merged 9 commits into from Nov 30, 2016

Conversation

travisoneill
Copy link
Collaborator

@travisoneill travisoneill commented Oct 3, 2016

DO NOT MERGE YET

Implements routes and controllers for servers with eos g service. Basic REST functionality up for Express. Generation command working.

FUNCTIONALITY:
Adds a default routes.js and controller.js file to the service folder on running eos g service express [name]. Users can easily map routes and REST verbs directly to controller actions simply by adding the route to /<server>/routes.js and writing the corresponding method in /<server>/controller.js

// /servername/routes.js
const GET = {
  '/': 'root',
  '/example': 'getExample'
  //<route>: <controller action>
};

const POST = {
  '/example': 'postExample'
  //<route>: <controller action>
};

// /servername/controller.js

  root(){
    return 'This is the Root';
  }

   getExample(){
   //do stuff...
    return <Example  GET Response>;
  }

  root(){
    //do stuff...
    return <Example  POST Response>;
  }

TODO:

  1. Implement nested routes
  2. Implement URL params
  3. Handle POST request data
  4. Configure static file functionality for default server on eos g service
  5. Implement all of the above for Flask

@travisoneill
Copy link
Collaborator Author

Implemented routes for Flask.

FUNCTIONALITY:
Adds a default routes.py and controller.py file to the service folder on running eos g service flask [name]. Users can easily map routes and REST verbs directly to controller actions simply by adding the route to //routes.py and writing the corresponding method in //controller.py.

#/<name>/routes.py
from collections import defaultdict
GET = defaultdict(lambda: None)
POST = defaultdict(lambda: None)
PATCH_PUT = defaultdict(lambda: None)
DELETE = defaultdict(lambda: None)

GET['/'] = 'root'
GET['/test'] = 'test'

# To add routes:
# <METHOD>[<route>] = <controller action>

#/<name>/controller.py
def root():
    return 'ROOT'


def error(code):
    errors = {
        404: 'Route Not Found'
    }
    text = errors[code]
    return 'ERROR:  ' + str(code) + '  ' + text

TODO:

  1. Implement nested routes
  2. Implement URL params
  3. Handle POST request data
  4. Configure static file functionality for default server on eos g service

@travisoneill
Copy link
Collaborator Author

Nested routes and params now working for Flask and Express. Express route matching handled by module in /utils/routing.js. Flask routing handled by pip package eos_python_utils installed by the config script. Currently at https://github.com/travisoneill/python-utils-eos-redux.

TODO:

  1. Handle POST request data
  2. Configure static file functionality for default server on eos g service

@travisoneill travisoneill merged commit b27ce4f into alexmattson:master Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant