Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

ASP.NET---101 (REST)

About The purpose of this article is to provide you with practical, hands-on knowledge for building a REST API. We will walk through the essential components required for creating API endpoints, covering both data input and data output…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




About



The purpose of this article is to provide you with practical, hands-on knowledge for building a REST API.


We will walk through the essential components required for creating API endpoints, covering both data input and data output techniques.





Attributes



In ASP.NET Core, attributes define and control API behavior. They are placed above controller methods and provide metadata about how each endpoint should handle requests.



Commonly used attributes include:





  • [HttpGet], [HttpPost], [HttpPut], [HttpDelete] – Specify the HTTP method for an endpoint


  • [Route("path")] – Define a custom URL route


  • [FromBody], [FromQuery], [FromForm] – Control how parameters are bound


  • [Produces("application/json")] – Specify the response format
    ## Input Methods
    In this section, we explore how to receive data in a REST API.
    Different HTTP methods and scenarios require different binding techniques.
    Some inputs can be combined; others are specific to certain request types.
    ### Form Query
    Query parameters are appended to the URL and are useful for simple key-value data, especially for GET requests.



[HttpGet("FormQuery")]
public string FormQuery([FromQuery] string text)
{
return $"Your text form Query -> {text}";
}







Example request (cURL)





curl -X 'GET' \
'https://localhost:7291/api/MyBestApp/QueryExample?text=You_Are_Great' \
-H 'accept: text/plain'





You can also paste {Your_URL}/api/MyBestApp/QueryExample?text=You_Are_Great


directly into your browser’s address bar.





From Body



For sending complex or large amounts of data (e.g., objects, arrays), we use the request body—primarily with POST or PUT methods.




[HttpPost("FormBody")]
public string FormBody([FromBody] ExampleRequest request)
{
return String.Concat(Enumerable.Repeat(request.Text, request.Amount));
}









Example request (cURL)






curl -X 'POST' \
'https://localhost:7291/api/MyBestApp/BodyExample' \
-H 'accept: text/plain' \
-H 'Content-Type: application/json' \
-d '{
"text": "ASP.NET",
"amount": 5
}'










From Route



Route parameters are embedded directly in the URL path.




[HttpGet("FormRoute/{text}")]
public string FormRoute(string text)
{
return $"Your text form Query -> {text}";
}









Example request (cURL)






curl -X 'GET' \
'https://localhost:7291/api/MyBestApp/RouteExample/What%27s_up%3F' \
-H 'accept: text/plain'






As with query parameters, you can also call this endpoint directly in your browser.






Return types



So far, our examples have returned simple strings. However, return type choice affects control over HTTP status codes and response formatting.



Common return patterns:





  • Direct type (e.g., string) – Simple, but limited HTTP status control.


  • ActionResult<T> – Strongly typed response with full HTTP status control.


  • IActionResult – Flexible return type for varied responses.




[HttpPost("FormBodyActionResult")]
public ActionResult<string> FormBodyActionResult([FromBody] ExampleRequest request)
{
if (request.Amount < 0)
return new BadRequestObjectResult("Amount must be bigger that 0");

return Ok(String.Concat(Enumerable.Repeat(request.Text, request.Amount)));
}

[HttpPost("FormBodyIActionResult")]
public IActionResult FormBodyIActionResult([FromBody] ExampleRequest request)
{
if (request.Amount < 0)
return new BadRequestObjectResult("Amount must be bigger that 0");

return Ok(String.Concat(Enumerable.Repeat(request.Text, request.Amount)));
}









!Bonus!: How to upload file



ASP.NET Core supports file uploads using the [FromForm] attribute with IFormFile.




[HttpPost("FileUploadExample")]
public string FromForm(IFormFile file)
{
return $"Received: {file.FileName}, {file.ContentType}";
}









Summary



We explored the key elements of building a REST API in ASP.NET Core, including defining endpoints with attributes, receiving input from different sources, and returning structured responses. You also learned how to handle files through API endpoints. With these fundamentals, you can start creating functional, flexible, and well-structured APIs.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten ASP.NET---101 (REST)

Thematisch verwandte Begriffe: ASPNET101, REST · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-18163 | IBM Financial Transaction Manager (FTM) for RedHat OpenShift could allow…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick