我们可以在Node.js中的查询字符串中获取变量,就像我们$_GET在PHP中获取它们一样吗?
我知道在Node.js中我们可以在请求中获取URL.有没有获取查询字符串参数的方法?
我正在创建一个新的REST服务.
将参数传递给REST服务的标准是什么.从Java中的不同REST实现,您可以将参数配置为路径的一部分或作为请求参数.例如,
路径参数 http://www.rest.services.com/item/b
请求参数 http://www.rest.services.com/get?item=b
有谁知道传递参数的每种方法的优点/缺点.似乎将参数作为路径的一部分传递似乎与REST协议的概念更吻合.也就是说,单个位置表示唯一的响应,对吗?
我试过了
/// <summary>
/// Request the Facebook Token
/// </summary>
[FunctionName("SolicitaFacebookToken")]
[Route("SolicitaToken/?fbAppID={fbAppID}&fbCode={fbCode}&fbAppSecret={fbAppSecret}")]
public static async Task<HttpResponseMessage> SolicitaFacebookToken(
[HttpTrigger(AuthorizationLevel.Function, methods: new string[] { "get" } )]
HttpRequestMessage req,
TraceWriter log,
string fbAppID,
string fbCode,
string fbAppSecret
)
{ }
Run Code Online (Sandbox Code Playgroud)
当我访问URL时
http://localhost:7071/api/SolicitaFacebookToken/?fbAppID=ABC&fbCode=DEF&fbAppSecret=GHI
Run Code Online (Sandbox Code Playgroud)
但这会带来以下错误:
无法从Azure WebJobs SDK调用“ SolicitaFacebookToken”。是否缺少Azure WebJobs SDK属性?System.InvalidOperationException:无法从Azure WebJobs SDK调用'SolicitaFacebookToken'。是否缺少Azure WebJobs SDK属性?在Microsoft.Azure.WebJobs.JobHost.Validate(IFunctionDefinition函数,对象键)在异步Microsoft.Azure.WebJobs.JobHost.CallAsync(??)在异步Microsoft.Azure.WebJobs.Script.ScriptHost.CallAsync(String method,Dictionary异步Microsoft.Azure.WebJobs.Script.Host.FunctionRequestInvoker处的`2个参数,异步Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostManager.HandleRequestAsync(FunctionDescriptor function,HttpRequestMessage request,CancellationToken cancellingToken)处的异步参数。
如果我更改为
HttpRequestMessage req,
string fbAppID,
string fbCode,
string fbAppSecret,
TraceWriter log
Run Code Online (Sandbox Code Playgroud)
[14/04/2018 15:24:49]以下1个功能有误:
[14/04/2018 15:24:49] SolicitaFacebookToken:Microsoft.Azure.WebJobs.Host:错误索引方法'Function1.SolicitaFacebookToken'。Microsoft.Azure.WebJobs.Host:无法将参数“ fbAppID”绑定为字符串类型。确保绑定支持参数类型。如果您正在使用绑定扩展(例如ServiceBus,Timer等),请确保已在启动代码(例如config.UseServiceBus(),config.UseTimers()等)中调用了扩展的注册方法。 )。
在Azure Functions模板代码中,有
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q …Run Code Online (Sandbox Code Playgroud) 我正在努力寻找答案(也许是因为我没有正确提出问题)......
我正在构建 API 以公开我正在创建的基本社交网络服务的资源。我的理解是 API 中 URL 的结构本质上是一个层次结构,类似于目录的结构。我认为这意味着我可以有多个端点来访问相同的资源或资源链接集合。例如:
我有一个端点
www.domain.api.org/users/{:uid}/posts
这将返回用户发送的所有帖子或用户被标记的所有帖子。看起来没问题,但是如果我有一个端点,例如:
www.domain.api.org/posts
当使用 http GET 命中时,将返回所有公开帖子(即所有用户的帖子以及他的朋友和公开帖子)。
不同之处在于第一个 URL 指向用户拥有的资源,而第二个 URL 指向公共资源(当然包括用户发布的内容)这些是可以的还是我这样做是错误的/不太明智的方式?
重申一下,我可以有多个端点指向同一资源的不同上下文/视图吗?
我正在尝试从URL(看起来像https://something.com/card?id= uuid进入的地方)中获取一个uuid,然后使用该uuid来获取http get请求。
现在我有我的app.component.ts看起来像:
private cardUuid: string;
constructor(private service: AppService,
private route: ActivatedRoute){
let sub = this.route.params.subscribe((params: Params) => {
this.cardUuid = params['id'];
console.log(this.cardUuid)
})
}
ngOnInit(){
this.service.browserUuid = 'http://address/cards?uuid=' + this.sub.cardUuid;
console.log(this.sub.cardUuid)
Run Code Online (Sandbox Code Playgroud)
}
我的控制台日志返回为未定义。我想知道为什么会这样吗?获取uuid的方法是否错误或呼叫计时是否错误?
任何帮助/提示/建议将不胜感激。
更新: 根据@Alexander Staroselsky的建议,我重新构造了每个angular.io文档从url调用uuid的方法。
app.component.ts:
card: Card = {};
ngOnInit() {
this.route.paramMap
.switchMap((params: ParamMap) =>
this.service.fetchCardUuid(+params.get('id')))
.subscribe(
card => {
this.card = card;
this.getVenueUuid(this.card);
});
}
Run Code Online (Sandbox Code Playgroud)
app-service.ts:
public UuidUrl = 'http://websiteaddress/cards?uuid='
constructor(private http: Http){}
private extractData(res:Response) {
let body = res.json();
return body …Run Code Online (Sandbox Code Playgroud)