endpoints
This commit is contained in:
parent
a714c2a8c0
commit
966bab17b1
@ -1,6 +1,40 @@
|
|||||||
@Biblioteca_HostAddress = http://localhost:5000
|
@url = http://localhost:5000
|
||||||
|
|
||||||
GET {{Biblioteca_HostAddress}}/weatherforecast/
|
### Obtém uma lista de livros
|
||||||
|
|
||||||
|
GET {{url}}/livros
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
|
|
||||||
###
|
### Cria um novo livro
|
||||||
|
|
||||||
|
POST {{url}}/livros
|
||||||
|
Accept: application/json
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"isbn": "9780321741769",
|
||||||
|
"titulo": "The C# Programming Language",
|
||||||
|
"autor": "Anders Hejlsberg"
|
||||||
|
}
|
||||||
|
|
||||||
|
### Edita um livro
|
||||||
|
|
||||||
|
PUT {{url}}/livros/9780321741769
|
||||||
|
Accept: application/json
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"isbn": "9780321741769",
|
||||||
|
"titulo": "The C# Programming Language",
|
||||||
|
"autor": "Anders Hejlsberg, Mads Torgensen"
|
||||||
|
}
|
||||||
|
|
||||||
|
### Obtém um livro individual
|
||||||
|
|
||||||
|
GET {{url}}/livros/9780321741769
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
### Remove um livro
|
||||||
|
|
||||||
|
DELETE {{url}}/livros/9780321741769
|
||||||
|
Accept: application/json
|
||||||
@ -1,41 +1,71 @@
|
|||||||
var builder = WebApplication.CreateBuilder(args);
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
// Add services to the container.
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
||||||
builder.Services.AddOpenApi();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
app.MapGet("/", () =>
|
||||||
if (app.Environment.IsDevelopment())
|
|
||||||
{
|
{
|
||||||
app.MapOpenApi();
|
string[] saudacoes = ["Olá!", "こんにちは", "Привет", "Ողջույն"];
|
||||||
|
|
||||||
|
return saudacoes[Random.Shared.Next(saudacoes.Length)];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Obtém uma lista com os livros registrados.
|
||||||
|
app.MapGet("/livros", () =>
|
||||||
|
{
|
||||||
|
return new Livro[]
|
||||||
|
{
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Isbn = "9780262510875",
|
||||||
|
Titulo = "Structure and Interpretation of Computer Programs",
|
||||||
|
Autor = "Gerald Jay Sussman"
|
||||||
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Isbn = "9780131103627",
|
||||||
|
Titulo = "C Programming Language: ANSI C Version",
|
||||||
|
Autor = "Dennis Ritchie, Brian Kerningham"
|
||||||
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Isbn = "9780134190440",
|
||||||
|
Titulo = "The Go Programming Language",
|
||||||
|
Autor = "Brian Kerningham"
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
|
||||||
|
|
||||||
var summaries = new[]
|
|
||||||
{
|
|
||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
|
||||||
app.MapGet("/weatherforecast", () =>
|
// Cria um novo livro.
|
||||||
|
app.MapPost("/livros", (Livro livro) =>
|
||||||
{
|
{
|
||||||
var forecast = Enumerable.Range(1, 5).Select(index =>
|
return livro;
|
||||||
new WeatherForecast
|
});
|
||||||
(
|
|
||||||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
// Edita um livro.
|
||||||
Random.Shared.Next(-20, 55),
|
app.MapPut("/livros/{isbn}", (string isbn, Livro livro) =>
|
||||||
summaries[Random.Shared.Next(summaries.Length)]
|
{
|
||||||
))
|
return new { editando = isbn, dados = livro };
|
||||||
.ToArray();
|
});
|
||||||
return forecast;
|
|
||||||
})
|
// Obtém os dados de um livro individual.
|
||||||
.WithName("GetWeatherForecast");
|
app.MapGet("/livros/{isbn}", (string isbn) =>
|
||||||
|
{
|
||||||
|
return new Livro() { Isbn = isbn };
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove um livro.
|
||||||
|
app.MapDelete("/livros/{isbn}", (string isbn) =>
|
||||||
|
{
|
||||||
|
return Results.NoContent();
|
||||||
|
});
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
public class Livro
|
||||||
{
|
{
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
public string? Isbn { get; set; }
|
||||||
}
|
public string? Titulo { get; set; }
|
||||||
|
public string? Autor { get; set; }
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user