001/*
002 * Stallion Core: A Modern Web Framework
003 *
004 * Copyright (C) 2015 - 2016 Stallion Software LLC.
005 *
006 * This program is free software: you can redistribute it and/or modify it under the terms of the
007 * GNU General Public License as published by the Free Software Foundation, either version 2 of
008 * the License, or (at your option) any later version. This program is distributed in the hope that
009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
011 * License for more details. You should have received a copy of the GNU General Public License
012 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
013 *
014 *
015 *
016 */
017
018package io.stallion.plugins.javascript;
019
020import io.stallion.restfulEndpoints.RestEndpointBase;
021import io.stallion.restfulEndpoints.JavascriptRequestHandler;
022import io.stallion.restfulEndpoints.RequestArg;
023
024/**
025 * Created by pfitzsimmons on 7/26/14.
026 *
027 EndPoint('route/:post_id', 'POST')
028 .bodyArg('state').queryArg('option')
029 .requireRole('public')
030 .requireXSRFToken(True)
031 .handler(function(post_id, state, option) {
032
033 });
034 */
035public class JsEndpoint extends RestEndpointBase {
036    private JavascriptRequestHandler _handler;
037
038    public JsEndpoint() {
039
040    }
041
042    public JsEndpoint(String route) {
043        this(route, "GET");
044    }
045
046    public JsEndpoint(String route, String method) {
047        setRoute(route);
048        setMethod(method);
049    }
050
051    public JsEndpoint bodyParam(String name) {
052        this.getArgs().add(new RequestArg().setName(name).setType("BodyParam"));
053        return this;
054    }
055
056    public JsEndpoint queryParam(String name) {
057        this.getArgs().add(new RequestArg().setName(name).setType("QueryParam"));
058        return this;
059    }
060
061    public JsEndpoint pathParam(String name) {
062        this.getArgs().add(new RequestArg().setName(name).setType("PathParam"));
063        return this;
064    }
065
066    public JsEndpoint mapParam() {
067        this.getArgs().add(new RequestArg().setType("MapParam"));
068        return this;
069    }
070
071    public JavascriptRequestHandler getHandler() {
072        return _handler;
073    }
074
075    public JsEndpoint setHandler(JavascriptRequestHandler handler) {
076        this._handler = handler;
077        return this;
078    }
079
080    public JsEndpoint handler(JavascriptRequestHandler handler) {
081        setHandler(handler);
082        return this;
083    }
084}