python - Question Regarding API Design -
i in process of researching best "design-pattern" web api. using django web framework. created non-ajax interface causes entire page reload @ each request.
now, starting incorporate ajax interface. sake of discussion, 2 example pieces of functionality need add api following
1) beta page: user supplies email address. want make ajax call serverside see if exists in db. initial design call view function similar to
def check_email(request): if request.method == "post": # check db # return json true/false 2) profile picture uploads, new profile picture added page without full page reload
as far can tell, best way via post call view function. then, response return json, can inject dom accordingly.
can please let me know if on right track designing api?
note: have checked out django-piston, , seems pretty useful also.
thanks
you're right on track, use request.is_ajax() check if it's ajax request return response accordingly. django request docs
returns true if request made via xmlhttprequest, checking http_x_requested_with header string 'xmlhttprequest'. modern javascript libraries send header. if write own xmlhttprequest call (on browser side), you'll have set header manually if want is_ajax() work.
this allow separate return values users have javascript disabled, allowing them still use site correctly. if you're not using javascript library, set yourself.
Comments
Post a Comment