Skip to content

Commit 0b51b7b

Browse files
authored
Add Testing Resources Documentation (#42)
1 parent ea8ef61 commit 0b51b7b

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

docs/docs/testing-resources.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
sidebar_position: 15
3+
title: Testing Resources
4+
---
5+
6+
When you're exploring FluentHttpClient for the first time, it's helpful to have a simple, predictable API to call without needing to stand up your own backend. A great option for this is **JSONPlaceholder**, a free, public REST API designed specifically for testing and prototyping:
7+
8+
**[https://jsonplaceholder.typicode.com](https://jsonplaceholder.typicode.com)**
9+
10+
JSONPlaceholder provides stable, well-defined endpoints for common resources (posts, comments, users, etc.). Since these endpoints always return consistent data and never modify real state, they're perfect for demonstrating FluentHttpClient's request building workflow and testing different serialization patterns.
11+
12+
**Why JSONPlaceholder Works Well with FluentHttpClient**
13+
14+
* It offers real HTTP responses - no mocks required.
15+
* You can test GET, POST, PUT, PATCH, and DELETE requests safely.
16+
* It accepts JSON input and returns JSON output
17+
* You can experiment without worrying about breaking anything.
18+
19+
## Basic Usage
20+
21+
Below is an example that retrieves a post, creates a new one, and deserializes JSON responses into strongly-typed models.
22+
23+
```csharp
24+
public sealed class Post
25+
{
26+
public int Id { get; set; }
27+
public int UserId { get; set; }
28+
public string? Title { get; set; }
29+
public string? Body { get; set; }
30+
}
31+
```
32+
33+
### Fetching a Single Post
34+
35+
```csharp
36+
var client = new HttpClient
37+
{
38+
BaseAddress = new Uri("https://jsonplaceholder.typicode.com")
39+
};
40+
41+
var post = await client
42+
.UsingBase()
43+
.WithRoute("posts/1")
44+
.SendAsync()
45+
.ReadJsonAsync<Post>();
46+
47+
Console.WriteLine(post?.Title);
48+
```
49+
50+
### Fetching a List of Posts
51+
52+
```csharp
53+
var posts = await client
54+
.UsingBase()
55+
.WithRoute("posts")
56+
.SendAsync()
57+
.ReadJsonAsync<List<Post>>();
58+
59+
Console.WriteLine(posts?.Count);
60+
```
61+
62+
### Creating a Post
63+
64+
JSONPlaceholder won't actually store your changes, but it simulates success and returns the created object.
65+
66+
```csharp
67+
var newPost = new Post
68+
{
69+
UserId = 1,
70+
Title = "Hello FluentHttpClient",
71+
Body = "Testing JSONPlaceholder"
72+
};
73+
74+
var created = await client
75+
.UsingBase()
76+
.WithRoute("posts")
77+
.WithJsonContent(newPost)
78+
.PostAsync()
79+
.ReadJsonAsync<Post>();
80+
81+
Console.WriteLine(created?.Id);
82+
```
83+
84+
## Trying Other Endpoints
85+
86+
JSONPlaceholder supports additional routes like:
87+
88+
* `/comments`
89+
* `/albums`
90+
* `/photos`
91+
* `/todos`
92+
* `/users`
93+
94+
All of them work the same way with FluentHttpClient - configure, send, and deserialize.

0 commit comments

Comments
 (0)