Z
Z
zlodiak2019-04-26 11:14:37
Python
zlodiak, 2019-04-26 11:14:37

What is the correct way to name rest functions?

Please tell me how to correctly call the functions in the rest-service. The question is not very important because the service will work without problems with any names, but I would like to know what are the established solutions for the case of working with flask.
Here is my attempt:

@app.route('/users', methods=['GET'])
def get_users():
    return 'get all users'

@app.route('/user/<id>', methods=['GET', 'POST'])
def user_id(id):
    if request.method == 'GET':
        return 'edit user' + str(id)
    elif request.method == 'POST':
        return 'edit user' + str(id)

@app.route('/user', methods=['POST'])
def create_user():
    return 'create new user'

@app.route('/user/<id>', methods=['DELETE'])
def delete_user(id):
    return 'delete user' + str(id)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pcdesign, 2019-04-26
@pcdesign

Actually, this is a serious question.
How to name functions correctly, how to name variables correctly?
A certain number of pages in books are devoted to this issue: "Perfect code", "Clean code: creation, analysis and refactoring", etc. If you decide to connect perfectionism, then you should study these books, at least the relevant chapters.
In general, the problem with the correct naming is inherent in all languages.
And specifically with the design, yes there are certain standards. For example, there are languages ​​where the camel's hump is accepted - getUserId (), in python they mainly use underscore - get_user_id. But this, IMHO, is trifles.

R
Roman Kitaev, 2019-04-26
@deliro

You don't have any REST here. First figure out what it is

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question