All Projects → Taluu → Behapi

Taluu / Behapi

Licence: mit
Behat extension for those who want to write acceptances tests for apis

Projects that are alternatives of or similar to Behapi

Behat Api Extension
API extension for Behat, used to ease testing of JSON-based APIs
Stars: ✭ 92 (+217.24%)
Mutual labels:  api, rest, behat
Postman Bdd
A BDD test framework for Postman and Newman
Stars: ✭ 139 (+379.31%)
Mutual labels:  api, rest, bdd
Bicing Api
Get statistics and locations of bicycle stations through REST API
Stars: ✭ 149 (+413.79%)
Mutual labels:  api, bdd, behat
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+2613.79%)
Mutual labels:  api, rest
Just Api
💥 Test REST, GraphQL APIs
Stars: ✭ 768 (+2548.28%)
Mutual labels:  api, rest
Parallec
Fast Parallel Async HTTP/SSH/TCP/UDP/Ping Client Java Library. Aggregate 100,000 APIs & send anywhere in 20 lines of code. Ping/HTTP Calls 8000 servers in 12 seconds. (Akka) www.parallec.io
Stars: ✭ 777 (+2579.31%)
Mutual labels:  api, rest
Postgrest Starter Kit
Starter Kit and tooling for authoring REST API backends with PostgREST
Stars: ✭ 657 (+2165.52%)
Mutual labels:  api, rest
Api Platform
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
Stars: ✭ 7,144 (+24534.48%)
Mutual labels:  api, rest
Deno Drash
A REST microframework for Deno's HTTP server with zero 3rd party dependencies.
Stars: ✭ 795 (+2641.38%)
Mutual labels:  api, rest
Tinyme
A tiny php framework based on flight and medoo with restful api service
Stars: ✭ 28 (-3.45%)
Mutual labels:  api, rest
Bdd Experiment
An experiment on BDD in Symfony2 using Behat, Mink and Zombie.js
Stars: ✭ 12 (-58.62%)
Mutual labels:  bdd, behat
Cortex
Cortex: a Powerful Observable Analysis and Active Response Engine
Stars: ✭ 676 (+2231.03%)
Mutual labels:  api, rest
Rest Api Nodejs Mongodb
A boilerplate for REST API Development with Node.js, Express, and MongoDB
Stars: ✭ 672 (+2217.24%)
Mutual labels:  api, rest
Apidoc
RESTful API 文档生成工具,支持 Go、Java、Swift、JavaScript、Rust、PHP、Python、Typescript、Kotlin 和 Ruby 等大部分语言。
Stars: ✭ 785 (+2606.9%)
Mutual labels:  api, rest
Apistar
The Web API toolkit. 🛠
Stars: ✭ 5,605 (+19227.59%)
Mutual labels:  api, rest
Goyave
🍐 Elegant Golang REST API Framework
Stars: ✭ 811 (+2696.55%)
Mutual labels:  api, rest
Django apistar
Django App to integrate API Star's routes and views into Django's ecossystem.
Stars: ✭ 25 (-13.79%)
Mutual labels:  api, rest
Chakram
REST API test framework. BDD and exploits promises
Stars: ✭ 912 (+3044.83%)
Mutual labels:  rest, bdd
Apipie
Transform api declaration to js object for frontend. Inspired by VueRouter, koa-middleware and axios.
Stars: ✭ 29 (+0%)
Mutual labels:  api, rest
Bridge Deprecated
[DEPRECATED]: Prefer Retrofit/OkHttp by Square, or Fuel for Kotlin
Stars: ✭ 624 (+2051.72%)
Mutual labels:  api, rest

Behapi

Behat extension to help write describe features related to HTTP APIs.

PHP 7.3, Behat 3.7 and a discoverable php-http client are required to make this extension work.

Installing this extension requires you to require taluu/behapi and an implementation of a http client (providing psr/http-client-implementation ^1.0, psr/http-factory-implementation ^1.0 and psr/http-message-implementation ^1.0).

You can find some examples on the examples/ directory.

Howto

Add this in your behat.yml (it's for the default configuration but you can use it for any configurations actually) :

default:
  suites:
    main:
      paths: ['%paths.base%/features']
      services: '@Behapi\Container'
      autowire: true

      contexts:
        #- List
        #- your
        #- contexts
        #- here

        # examples :
        - Behapi\Http\RequestContext: ~
        - Behapi\Http\ResponseContext: ~

  extensions:
    Behapi\Behapi:
      base_url: 'http://localhost'

The base_url is the only requirement in the config for this extension to work.

There are other configurations keys, such as which formatter to use in a debug environment, which headers you want to output in request or response while debugging ; Use the --config-reference flag when invoking behat to have more information on the available configuration.

After having installed the extension, you can then use the provided contexts such as the Behapi\Http\RequestContext for the http api operations. In order to use them, you need to use behapi's container (@Behapi\Container), or a container capable of using behapi's container.

Some services are provided to be injected in contexts, which are the following:

  • @Http\Client\Common\PluginClientBuilder, which will build a Http\Client\Common\PluginClient when needed
  • @Behapi\HttpHistory\History, which is a sort of a container with the last requests done and last responses received
  • @Http\Message\MessageFactory
  • @Http\Message\StreamFactory

Note: You don't really need to bother with the services names, as they are compatible with behat's auto-wiring feature.

In order to enable the Json assertions, you need to use the Behapi\Context\Json context. Note that if you use the json context, you should have used the client provided by the client builder used in the Behapi\Http\RequestContext context.

If you need to play with the request being built, or the response created when the request is sent, you need to inject the @Behapi\HttpHistory\History. It is automatically reseted between scenarios (and scenarios outlines)

A documentation will be made (soon hopefully) with more details.

Contributing

Contributing (issues, pull-requests) are of course always welcome ! Be sure to respect the standards (such as psr-2, ... etc), follow proper git etiquette (atomic commits, ...), proper conduct too and it should be fine !

Thanks

This extension was made while I was working at @Wisembly, and heavily used for writing our features and integration tests. Special thanks goes to @lunika, @rgazelot and @krichprollsch, who helped conceived this extension, and also pushed me to open-source it.

Badges

Type Coverage

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].