c# - What is the 'api_key' and how do I use it correctly -
i'm new restful services, , i've implemented test code servicestack restful service going swagger plugin working well, leads me question...
inside swagger-ui/index.html there field 'api_key'. know variable name umm... variable, , can set whatever like, i'm confused it's used , whether should making use of it.
also, if use it, how servicestack present value me on server side?
here test service i've got , running documentation...
[api("hello web services")] [route("/hello", summary = @"noel's servicestackswagger thingy", notes = "some more info in here cause these notes")] [route("/hello/{name}", summary = @"n031'5 servicestackswagger thingy", notes = "some more info in here cause these notes", verbs="get,post" )] public class hello { [apimember(name = "name", description = "this description", parametertype = "path", datatype = "string", verb="get,post")] public string name { get; set; } } public class helloresponse { public string result { get; set; } } public class helloservice : service { public object any(hello request) { return new helloresponse { result = "hello, " + request.name }; } }
to answer own follow request of esker, here how use api key thingy...
public class helloservice : service { public object any(hello request) { string api_key = this.request.headers["api_key"]; return new helloresponse { result = "hello, " + request.name }; } }
but required javascript include in header (inside swagger-ui/index.html)...
$(function () { $.ajaxsetup({ beforesend: function (jqxhr, settings) { jqxhr.setrequestheader("api_key", $("#input_apikey").val()); } }); });
which found in answer in question...
Comments
Post a Comment