我已经设置了我的第一个REST API,而且我是使用Taffy框架的新手.
我有一个网站正在使用ColdFusion 10,IIS和使用ColdBox.我在目录中设置了一个hello world示例.我//在回复中得到两个斜线.以下是响应的示例:
//["hello","world"]
Run Code Online (Sandbox Code Playgroud)
我的hello.cfc看起来像这样:
component extends="taffy.core.resource" taffy_uri="/hello" {
function get(){
return representationOf(['hello','world']);
}
}
Run Code Online (Sandbox Code Playgroud)
我的application.cfc看起来像这样:
<cfcomponent extends="taffy.core.api">
<cfscript>
this.name = hash(getCurrentTemplatePath());
this.mappings["/resources"] = listDeleteAt(cgi.script_name, listLen(cgi.script_name, "/"), "/") & "/resources";
variables.framework = {};
variables.framework.reloadKey = "reload";
variables.framework.reloadPassword = "test";
variables.framework.serializer = "taffy.core.nativeJsonSerializer";
variables.framework.returnExceptionsAsJson = true;
function onApplicationStart(){
return super.onApplicationStart();
}
function onRequestStart(TARGETPATH){
// reload app to make any envoirnmental changes
if(structkeyexists(url,'reloadApp')){
applicationStop();
location('index.cfm');
}
// load Taffy onRequestStart before our stuff
super.onRequestStart();
if (request.taffyReloaded) {
// …Run Code Online (Sandbox Code Playgroud) 在服务器上,有什么方法可以区分内部和外部 REST API 请求吗?
为什么?
我想区分这两个来源的原因是,根据受访者给出的建议,我可能想要返回不同的数据集,具体取决于谁试图发出请求。
概括
我对内部的定义可能不正确。在这种情况下,“内部”是指从与处理该请求的页面相同的域的 XHTTP 请求发出的请求。
外部调用可能是用户从另一个域创建 Curl 请求。
例如:
http.service.ts
内部角度 6 请求
fetchLogin(formData: any): Observable<any> {
let req = null;
let headers = null;
headers = {
reportProgress: false,
headers: new HttpHeaders({
'email': formData['email'],
'password': formData['password']
})
};
req = new HttpRequest('POST', this.restApiUrl + this.restApiUrlEndpoint + '/oauth/', '', headers);
return this.http.request(req)
.map( (data) => {
return 'body' in data ? data['body'] : null;
})
.pipe(
catchError(this.handleError)
);
}
Run Code Online (Sandbox Code Playgroud)
模板.cfm
外部冷聚变请求
<cfset httpUrl = request.restApiUrl …Run Code Online (Sandbox Code Playgroud)