https://github.com/banane9/apepi
Library for creating a HTTP API that is based on your class model.
https://github.com/banane9/apepi
Last synced: 4 months ago
JSON representation
Library for creating a HTTP API that is based on your class model.
- Host: GitHub
- URL: https://github.com/banane9/apepi
- Owner: Banane9
- License: lgpl-2.1
- Created: 2014-10-02T09:36:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-09-17T10:49:07.000Z (almost 10 years ago)
- Last Synced: 2025-01-15T01:42:22.759Z (5 months ago)
- Language: C#
- Size: 164 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
ApePI
=====Library for creating a HTTP API that is based on your class model.
The API would be created from the class model as follows:
``` CSharp
// Root /
[NoEndpoint]
public sealed class Root
{
// /players will try to return the Players object,
// but it can't because of the NoStop attribute on the class
public Players Players { get; private set; }
// /settings will return the Settings object - public GET and authorized POST
// Can either be POSTed as Settings object or individual settings (name, etc.)
public Settings Settings { get; internal set; }
}// NoEndpoint tells it that it can't be returned directly (i.e. it isn't an endpoint)
[NoEndpoint]
public sealed partial class Players
{
// Key = player.Login
private Dictionary playersL;
// Key = player.Id
private Dictionary playersI;
// /players/{login} will return a Player object - public GET only
public Player this[string login]
{
get { return playersL[login]; }
}
// /players/{id} will return a Player object - public GET only
public Player this[uint id]
{
get { return playersI[id]; }
}
}// Player object ( /players/{(login|id)} )
[JsonObject]
public sealed class Player
{
// /players/{(login|id)}/login will return the player login - public GET only
public string Login { get; private set; }
// /players/{(login|id)}/id will return the player id - public GET only
public uint Id { get; private set; }
// /players/{login}/banned will return whether the player is banned
// - public GET and authorized POST
public bool Banned { get; internal set; }
}// Settings object ( /settings )
[JsonObject]
public sealed class Settings
{
// /settings/name will return the name - public GET and authorized POST
public string Name { get; internal set; }
// /settings/maxplayers will return the max players - public GET and authorized POST
public uint MaxPlayers { get; internal set; }
}
```All parts of the path that are based on the classes are case insensitive and parameters depend on their implementation.
Query/Post parameters could be used for functions:
``` CSharp
public sealed partial class Players
{
// /players/all?offset=0&length=20 will return the first 20 players - public GET (authorized GET when internal)
// POST would be PostAll, etc.
public IEnumerable GetAll(uint offset, uint length)
{
return playersI.Skip(offset).Take(length);
}
}
```