Skip to content

storinka/invoke-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

home title heroImage heroImageDark heroText actions features
true
Home
/images/logo.png
/images/logo_dark.png
text link type
Get Started
/guide/getting-started.html
primary
text link type
Explore APIs
secondary
title details
Fast
Invoke allows you to build fast APIs and deploy them in minutes.
title details
Modern
TODO
title details
Simple
TODO
title details
100% typed
Invoke allows you to create fully typed APIs without pain.
title details
Super-flexible
Invoke provides absolutely new way of creating backends with extremely high level of flexibility.
title details
Self-documented
Just write a code that works and Invoke will generate the documentation for you.

Example 1:

Create a function:

function sayHelloTo(string $name): string
{
    return "Hello, $name!";
}

Setup Invoke:

use Invoke\Invoke;

Invoke::create([
    "sayHelloTo",
])->serve();

Start a server, invoke the function:

curl "localhost/invoke/sayHelloTo?name=Kitty"

# response will be: { "result": "Hello, Kitty!" }

Example 2:

Create Post and Comment types:

use Invoke\Data;
use Invoke\Toolkit\Validators\ArrayOf;

class PostResult extends Data
{
    public int $id;
    
    public string $title;
    
    #[ArrayOf(CommentResult::class)]
    public array $comments;
}
use Invoke\Data;
use Invoke\Toolkit\Validators\Length;

class CommentResult extends Data
{
    public int $id;
    
    public string $message;
}

class CommentInput extends Data
{
    #[Length(min: 3, max: 255)]
    public string $message;
}

Create methods for getting posts and creating comments:

use Invoke\Method;

class GetPosts extends Method
{
    protected PostsRepository $postsRepository;

    public function __construct(PostsRepository $postsRepository)
    {
        $this->postsRepository = $postsRepository;
    }

    protected function handle(): array
    {
        $posts = $this->postsRepository->getWithComments();
    
        return PostType::many($posts);
    }
}

class CreateComment extends Method
{
    protected CommentsRepository $commentsRepository;

    public function __construct(CommentsRepository $commentsRepository)
    {
        $this->commentsRepository = $commentsRepository;
    }

    protected function handle(int $postId, CommentInput $comment): CommentResult
    {
        $newComment = $this->commentsRepository->create($postId, $comment);
    
        return CommentResult::from($newComment);
    }
}

Setup Invoke:

use Invoke\Invoke;

Invoke::create([
    "getPosts" => GetPosts::class,
    "createComment" => CreateComment::class,
])->serve();

Start a server, invoke the functions:

curl "localhost/invoke/getPosts"
curl -X POST "localhost/invoke/createComment" \
  --data '{ "postId": 123, comment: { "message: "Great post!" } }'

About

Invoke documentation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •