Jump to content

Recommended Posts

Posted (edited)

About AutoIt-API-WS

AutoIt-API-WS is a light weight web server with expressive syntax, with the sole purpose of wrapping your existing AutoIt app with little to no effort.

With AutoIt-API-WS you can send and receive data between any application or framework, as long they can handle HTTP requests, which is an industry standard today.

Like my other communcations UDF AutoIt-Socket-IO AutoIt-API-WS is heavily inspired from the big boys, but this time its Laravel and Ruby on Rails.

Features Highlights

  • No external or internal dependencies required
  • RESTful mindset when designed
  • Expressive syntax
  • Small codebase
  • Heavy use of Michelsofts Dictionary object

Limitations

  • Not complient with any RFC, so something important could be missing. Time will tell!
  • One persons slow loris attack will kill the process forever.

Example of implemetnation (With screenshots)

This is a basic cRud operation with the RESTful mindset in use.

#include "API.au3"
#include <Array.au3>

_API_MGR_SetName("My APP DB adapter")
_API_MGR_SetVer("1.0 BETA")
_API_MGR_SetDescription("This adapter allows you to get this n that")

_API_MGR_Init(3000)
_API_MGR_ROUTER_GET('/users', CB_GetUsers, 'string sortBy', 'Get all users, sortBy can be either asc or desc. asc is default')
_API_MGR_ROUTER_GET('/users/{id}', CB_GetUsersById, 'int id*', 'Get user by id')

While _API_MGR_ROUTER_HANDLE()
WEnd

Func DB_GetUsers()
	Local $userA = ObjCreate("Scripting.Dictionary")
	Local $userB = ObjCreate("Scripting.Dictionary")

	$userA.add('id', 1)
	$userA.add('name', 'TarreTarreTarre')
	$userA.add('age', 27)

	$userB.add('id', 2)
	$userB.add('name', @UserName)
	$userB.add('age', 22)

	Local $aRet = [$userA, $userB]

	Return $aRet
EndFunc

Func CB_GetUsers(Const $oRequest)
	Local $aUsers = DB_GetUsers()

	If $oRequest.exists('sortBy') Then

		Switch $oRequest.item('sortBy')
			Case Default
			Case 'asc'

			Case 'desc'
				_ArrayReverse($aUsers)
		EndSwitch

	EndIf

	Return $aUsers

EndFunc

Func CB_GetUsersById(Const $oRequest)

	Local Const $aUsers = DB_GetUsers()
	Local $foundUser = Null

	For $i = 0 To UBound($aUsers) -1

		Local $curUser = $aUsers[$i]

		If $curUser.item('id') == $oRequest.item('#id') Then
			$foundUser = $curUser
			ExitLoop
		EndIf

	Next

	If Not IsObj($foundUser) Then
		Return _API_RES_NotFound(StringFormat("Could not find user with ID %d", $oRequest.item('#id')))
	EndIf

	return $foundUser

EndFunc

When you visit http://localhost:3000 you are greeted with this pleasent view that will show you all your registred routes and some extra info you have provided.

Doc preview

When you visit http://localhost:3000/users the UDF will return the array of objects as Json

User preview 

And here is an example of http://localhost:3000/users/1

User specified

 

More examples can be found here

 

 (NEWEST 2020-09-21)

Autoit-API-WS-1.0.3-beta.zip

OLD VERSIONS

Autoit-API-WS-1.0.0-beta.zip Autoit-API-WS-1.0.1-beta.zip

 

Edited by tarretarretarre
Posted

I have released 1.0.1-beta

Bugfixes

  • Empty array/object responses would not serialize properly
  • Empty strings keys would not get serialized propertly

Changes

  • The router now lazily accepts appended slashes (example: http:/localhost:4545/route/)

New

  • Added some lousy tests, see "Testing.au3" for more info
Posted (edited)

I have released 1.0.3-beta

Bugfixes

  • Ip adresses were parsed as numbers due to stupid regex check
  • Packet buffer dropped due to logical error
  • CRLF -> LF conversion to not break regex

Changes

New

Edited by tarretarretarre
  • 1 month later...
  • 1 year later...
Posted

How can i access request body? It seems like none of those example scripts demonstrate this... or please tell me if i've missed something.
Great work btw!

  • 10 months later...
  • 3 months later...
Posted
On 1/8/2023 at 3:44 PM, noellarkin said:

How well does this server do when it comes to concurrent access? Say 20-30 users accessing it at the same time.

I've conducted a stress test on this UDF (I don't have it any more as I erased it with my last Windows reinstallation). Well, the result is disappointing, for just 5-10 concurrent connections, the server begins to randomly reject/ignore requests if it is currently processing another request. So I highly doubt that the server can handle 20-30 users, according to your needs. I recommend you try out HttpAPI UDF as it will correctly queue requests even on large numbers of concurrent connections.

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...