- Hands-On Full:Stack Web Development with ASP.NET Core
- Tamir Dresher Amir Zuker Shay Friedman
- 243字
- 2021-06-10 19:37:30
Query strings
A query string is data that's sent as part of the URL that is not suitable for use as part of the hierarchical structure of the URL (where / separates between different levels of the hierarchy). Typically, the query string is the part that comes after the question mark in the URL and uses the & sign to separate between the different values. For example, the GiveNTake application allows the user to search for products in a specific location, and to constraint the search only to products that have an image attached to them. This API is exposed through a URL in the following format:
/api/products/searchcategory/category/subcategory?location=XXX&imageonly=true
ASP.NET Core automatically matches any value in the query string to a method parameter with the same name (this value is case-insensitive); therefore, the method in the controller is implemented like this:
[HttpGet("searchcategory/{category}/{subcategory=all}/")]
public string[] SearchByProducts(string category,string subcategory, string location="all", bool imageOnly=false )
{
return new[]
{
$"Category: {category}, Subcategory: {subcategory}, Location: {location}, Only with Images: {imageOnly}"
};
}
Run the application and navigate to
http://localhost:[port]/api/products/searchcategory/furniture/kitchen?location=center&imageonly=true.
Your browser should show a result similar to this:

- 從區(qū)塊鏈到Web3:構(gòu)建未來互聯(lián)網(wǎng)生態(tài)
- 網(wǎng)管員典藏書架:網(wǎng)絡(luò)管理與運(yùn)維實(shí)戰(zhàn)寶典
- 新一代物聯(lián)網(wǎng)架構(gòu)技術(shù):分層算力網(wǎng)絡(luò)
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- 網(wǎng)絡(luò)的琴弦:玩轉(zhuǎn)IP看監(jiān)控
- 中國互聯(lián)網(wǎng)發(fā)展報告2018
- 基于性能的保障理論與方法
- 4G小基站系統(tǒng)原理、組網(wǎng)及應(yīng)用
- jQuery Mobile Web Development Essentials
- TD-LTE無線網(wǎng)絡(luò)規(guī)劃與設(shè)計
- Learning Windows 8 Game Development
- 5G時代的大數(shù)據(jù)技術(shù)架構(gòu)和關(guān)鍵技術(shù)詳解
- 云工廠:開啟中國制造云時代
- LwIP應(yīng)用開發(fā)實(shí)戰(zhàn)指南:基于STM32
- 物聯(lián)網(wǎng)基礎(chǔ)及應(yīng)用