Skip to content

完整 API 参考

这里汇总了 Swit 框架中所有服务的 API 接口文档,方便您快速查找和使用。

服务概览

服务名称描述端点数量版本
SWIT Server APIThis is the SWIT server API documentation.51.0
SWIT Auth APIThis is the SWIT authentication service API documentation.51.0

SWIT Server API

This is the SWIT server API documentation.

  • 基础 URL: http://localhost:8080/
  • 版本: 1.0
  • 端点数量: 5

internal

POST /internal/validate-user

Validate user credentials (Internal API)

Internal API for validating user credentials, used by authentication service

方法路径
POST/internal/validate-user

参数

参数名类型必填/可选描述
credentialsobject必填User credentials

响应

状态码描述
200Validation successful
400Bad request
401Invalid credentials
500Internal server error

示例

:::tabs

== cURL

bash
curl -X POST \
  "http://localhost:8080/internal/validate-user" \
  -d '{"key": "value"}'

== JavaScript

javascript
const response = await fetch('http://localhost:8080/internal/validate-user', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
  },
  body: JSON.stringify({ key: 'value' }),
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.post(
    'http://localhost:8080/internal/validate-user',
    json={'key': 'value'},
    headers=headers
)
data = response.json()
print(data)

:::

users

POST /users/create

Create a new user

Create a new user with username, email and password

方法路径
POST/users/create

参数

参数名类型必填/可选描述
userobject必填User information

响应

状态码描述
201User created successfully
400Bad request
500Internal server error

示例

:::tabs

== cURL

bash
curl -X POST \
  "http://localhost:8080/users/create" \
  -d '{"key": "value"}'

== JavaScript

javascript
const response = await fetch('http://localhost:8080/users/create', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
  },
  body: JSON.stringify({ key: 'value' }),
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.post(
    'http://localhost:8080/users/create',
    json={'key': 'value'},
    headers=headers
)
data = response.json()
print(data)

:::

GET /users/email/

Get user by email

Get user details by email address

方法路径
GET/users/email/{email}

参数

参数名类型必填/可选描述
emailstring必填Email address

响应

状态码描述
200User details
404User not found
500Internal server error

示例

:::tabs

== cURL

bash
curl -X GET \
  "http://localhost:8080/users/email/{email}

== JavaScript

javascript
const response = await fetch('http://localhost:8080/users/email/{email}', {
  headers: {
    'Authorization': 'Bearer <your_token>',
  },
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.get(
    'http://localhost:8080/users/email/{email}',
    headers=headers
)
data = response.json()
print(data)

:::

GET /users/username/

Get user by username

Get user details by username

方法路径
GET/users/username/{username}

参数

参数名类型必填/可选描述
usernamestring必填Username

响应

状态码描述
200User details
404User not found
500Internal server error

示例

:::tabs

== cURL

bash
curl -X GET \
  "http://localhost:8080/users/username/{username}

== JavaScript

javascript
const response = await fetch('http://localhost:8080/users/username/{username}', {
  headers: {
    'Authorization': 'Bearer <your_token>',
  },
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.get(
    'http://localhost:8080/users/username/{username}',
    headers=headers
)
data = response.json()
print(data)

:::

DELETE /users/

Delete a user

Delete a user by ID

方法路径
DELETE/users/{id}

参数

参数名类型必填/可选描述
idstring必填User ID

响应

状态码描述
200User deleted successfully
400Invalid user ID
500Internal server error

示例

:::tabs

== cURL

bash
curl -X DELETE \
  "http://localhost:8080/users/{id}

== JavaScript

javascript
const response = await fetch('http://localhost:8080/users/{id}', {
  method: 'DELETE',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
  },
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.delete(
    'http://localhost:8080/users/{id}',
    headers=headers
)
data = response.json()
print(data)

:::

SWIT Auth API

This is the SWIT authentication service API documentation.

  • 基础 URL: http://localhost:8090/
  • 版本: 1.0
  • 端点数量: 5

authentication

POST /auth/login

User login

Authenticate a user with username and password, returns access and refresh tokens

方法路径
POST/auth/login

参数

参数名类型必填/可选描述
loginobject必填User login credentials

响应

状态码描述
200Login successful
400Bad request
401Invalid credentials

示例

:::tabs

== cURL

bash
curl -X POST \
  "http://localhost:8080/auth/login" \
  -d '{"key": "value"}'

== JavaScript

javascript
const response = await fetch('http://localhost:8080/auth/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
  },
  body: JSON.stringify({ key: 'value' }),
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.post(
    'http://localhost:8080/auth/login',
    json={'key': 'value'},
    headers=headers
)
data = response.json()
print(data)

:::

POST /auth/logout

User logout

Invalidate the user's access token and log them out

方法路径
POST/auth/logout

响应

状态码描述
200Logout successful
400Authorization header is missing
500Internal server error

示例

:::tabs

== cURL

bash
curl -X POST \
  "http://localhost:8080/auth/logout

== JavaScript

javascript
const response = await fetch('http://localhost:8080/auth/logout', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
  },
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.post(
    'http://localhost:8080/auth/logout',
    headers=headers
)
data = response.json()
print(data)

:::

POST /auth/refresh

Refresh access token

Generate new access and refresh tokens using a valid refresh token

方法路径
POST/auth/refresh

参数

参数名类型必填/可选描述
refreshobject必填Refresh token

响应

状态码描述
200Token refresh successful
400Bad request
401Invalid or expired refresh token

示例

:::tabs

== cURL

bash
curl -X POST \
  "http://localhost:8080/auth/refresh" \
  -d '{"key": "value"}'

== JavaScript

javascript
const response = await fetch('http://localhost:8080/auth/refresh', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
  },
  body: JSON.stringify({ key: 'value' }),
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.post(
    'http://localhost:8080/auth/refresh',
    json={'key': 'value'},
    headers=headers
)
data = response.json()
print(data)

:::

GET /auth/validate

Validate access token

Validate an access token and return token information including user ID

方法路径
GET/auth/validate

响应

状态码描述
200Token is valid
401Invalid or expired token

示例

:::tabs

== cURL

bash
curl -X GET \
  "http://localhost:8080/auth/validate

== JavaScript

javascript
const response = await fetch('http://localhost:8080/auth/validate', {
  headers: {
    'Authorization': 'Bearer <your_token>',
  },
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.get(
    'http://localhost:8080/auth/validate',
    headers=headers
)
data = response.json()
print(data)

:::

health

GET /health

Health check

Check if the authentication service is healthy

方法路径
GET/health

响应

状态码描述
200Service is healthy

示例

:::tabs

== cURL

bash
curl -X GET \
  "http://localhost:8080/health

== JavaScript

javascript
const response = await fetch('http://localhost:8080/health', {
  headers: {
    'Authorization': 'Bearer <your_token>',
  },
});
const data = await response.json();
console.log(data);

== Python

python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_token>',
}

response = requests.get(
    'http://localhost:8080/health',
    headers=headers
)
data = response.json()
print(data)

:::

Released under the MIT License.