Jump to content

AutoIt-API-WS - An expressive HTTP server you can use to build your own API with (Screenshots)


Recommended Posts

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
Link to post
Share on other sites

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
Link to post
Share on other sites

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
Link to post
Share on other sites
  • 1 month later...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By mLipok
      This is TeamViewer.au3 UDF for TeamViewer API.
      ; #INDEX# ======================================================================== ; Title .........: TeamViewer.au3 ; AutoIt Version : 3.3.10.2++ ; Language ......: English ; Description ...: A collection of function for use with TeamViewer API ; Author ........: mLipok ; Modified ......: ; URL ...........: ; URL ...........: https://www.teamviewer.com/ ; URL ...........: https://www.teamviewer.com/en/integrations/ ; URL ...........: https://integrate.teamviewer.com/en/develop/api/get-started/ ; URL ...........: https://downloadeu1.teamviewer.com/integrate/TeamViewer_API_Documentation.pdf ; Remarks .......: This UDF was created based on TeamViewer_API_Documentation.pdf v 1.4.1 ; Remarks .......: This UDF is using Free Chilkat component look here https://www.autoitscript.com/forum/files/file/433-chilkat-udf/ ; Remarks .......: Documentation is "work in progress" ; Date ..........: 2017/02/08 ; Version .......: 0.1.1 BETA - Work in progress ; ================================================================================ in TeamViewer_Example.au3 you can see few examples:

       
      Func _Example() ; If not exist then create new INI file from template If Not FileExists('TeamViewer_Example.ini') Then FileCopy('TeamViewer_Example — Template.ini', 'TeamViewer_Example.ini') ; Read Access Token from INI Local $sTV_AccessToken = IniRead('TeamViewer_Example.ini', 'Settings', 'AccessToken', '') If $sTV_AccessToken = '' Then ; Your Access Token, can be left empty when OAuth (below) is configured. ; ClientId = <----------------- Create an app in your TeamViewer Management Console and insert the client ID to the INI ; ClientSecret = <------------- Insert your client secret to the INI ; AuthorizationCode = <-------- Visit https://webapi.teamviewer.com/api/v1/oauth2/authorize?response_type=code&client_id=YOUR$i_ClientIdHERE ; Login, grant the permissions (popup) and put the code shown in the AuthorizationCode variable to the INI Local $sTVOAuth_ClientID = IniRead('TeamViewer_Example.ini', 'OAuth2', 'ClientID', '') Local $sTVOAuth_ClientSecret = IniRead('TeamViewer_Example.ini', 'OAuth2', 'ClientSecret', '') _IECreate('https://webapi.teamviewer.com/api/v1/oauth2/authorize?response_type=code&client_id=' & $sTVOAuth_ClientID) ; Local $sTVOAuth_AuthorizationCode = IniRead('TeamViewer_Example.ini', 'OAuth2', 'authorizationCode', '') Local $sTVOAuth_AuthorizationCode = InputBox('AuthorizationCode', 'Please provide TV OAuth2 AuthorizationCode') If @error Then Return If $sTVOAuth_ClientID Then $sTV_AccessToken = _TVAPI_RequestOAuth2_AccessToken($sTVOAuth_ClientID, $sTVOAuth_ClientSecret, $sTVOAuth_AuthorizationCode) EndIf If $sTV_AccessToken Then _TVAPI_AccessToken($sTV_AccessToken) If _TVAPI_Ping() = True Then ; ping API to check connection and $sTV_AccessToken _Example_TeamViewer__1_Devices_SaveToFile() ;~ _Example_TeamViewer__2_Devices_ChangeDetails() ;~ _Example_TeamViewer__3_Devices_GetDevicesSingleID() ;~ _Example_TeamViewer__4_Reports_GetAllConnections() ;~ _Example_TeamViewer__5_Users_GetUserInfomation() ;~ _Example_TeamViewer__6_Groups_ListGroups() ;~ _Example_TeamViewer__7_Devices_AddDeleteDevice() Else MsgBox(0, '_TVAPI_Ping', "$v_Token or connection problem.") EndIf EndFunc ;==>_Example You can download it here:
      I'm using TeamViewer_Example.ini to store my secret tokens/keys.
      [Settings] AccessToken= [OAuth2] ClientID= ClientSecret= authorizationCode=  
    • By nacerbaaziz
      hello guys, please i need your help
      am trying to work with CreateWindowEx api, i created the window with it controls, also i setup the call back function
      i'am using WinMSGLoop to focus with the keyboard.
      here i have a problem, i hope that you can help me.
      on the controls i used the UDF that comme with the autoit, such as _GUIButton_Create, _GUIListBox_Create....
      but i can't find a STATIC control UDF, for that i used this

      local $h_ssrvlbl = _WinAPI_CreateWindowEx(0, "STATIC", "الخادم", BitOr($WS_VISIBLE, $WS_CHILD, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN), 250, 10, 100, 20, $hWnd)
      as you can see here, there is an arabic text, so here is the problem, the arabic text isn't show normally, what is the problem here?
      also i have  an other question about keyboard focus, when i used WinMSGLoop, it worked, but if i press alt+tab to switch windows or focus an other window and return back to my window, the focus of control is kill.
      can any one help me to solve that please?
      my code will be as file here with the include files
      i hope can any one help me here
      thanks in advance
       
      speed Test win.zip
    • By rcmaehl
      Hi all, 

      Recently my work swapped from Cisco CTIOS to Finesse. This completely threw me off as I had been automating the Win32 application and I had never done IUIAutomation before. As such I've been messing around with the API and will be adding code as I figure it out. While I do have Supervisor access, I will likely not be adding functions for those features yet.
      Currently Available Functions:
      User API - Query and Set User Info
      Dialog API - Query and Set Call and other Dialog Info
      Queue API - Query Assigned Queues
      Team API - Query Users in a Team


      Changelog:
       
      Download:
       
      Support:
      Support for this UDF can be obtained in my Discord Server
    • By genius257
      This is yet another HTTP server written in AutoIt3.
      Originally based on jvanegmond's POST HTTP Server.
      It is designed to be used either as is, or by scripts for a HTTP communication between any browser and AutoIt3.
      It can run PHP and AutoIt3 CGI, if setup in the settings ini file.
      Github repository
      AutoIt-HTTP-Server-master.zip
    • By Jahar
      Hi,
      I am new to Autoit, Kindly guide me. I wanted to send a message with HTTP/GET to the URL https://ghsff.it/. How to do so?
×
×
  • Create New...